Reputation: 7129
I need to pass a variable from an Activity to a GridView Adapter. What I tried was:
Declaring a method inside the activity:
public int getPoints()
{
return points;
}
The in the adapter I declared:
mainActivity sel= new mainActivity();
And finally I called the method using:
int myPoints = sel.getPoints();
But it always returns 0. What is wrong with the code?
Upvotes: 0
Views: 5387
Reputation: 2668
MyGridAdapter adapter = new MyGridAdapter(myVariable)
To update variable from your activity you can also create method in your adapter and call it adapter.updateMyVariable(newVariable);
Upvotes: 3
Reputation: 539
Create public static variable points in mainActivity and then call from adapter mainActivity.points.
Upvotes: 0