How to update the text of a button from inside a GridViewAdapter in Android both of which are on the same activity?
I have an activity in which there are 2 columns. The left column has a button displaying a dynamic integer. This dynamic integer is printed on this button as follows:
button.setText(GlobalVariables.getInstance().GetMyArrayList().size());
On the right hand column I have a GridView which is using a GridViewAdapter to inflate the layout. I have a separate "GridViewAdapter.java" file to inflate the layout. Therefore, I now have 2 Java files - One is my activity file and another is this GridViewAdapter file.
Inside this GridViewAdapter I have (for each grid element) 1 ImageView, 1 TextView and 1 Button which the ViewHolder is maintaining for me. The button which I am using here inside this Adapter also has an OnClickEventListener to handle the onClick method. On pressing this button I call a setter function which is globally accessible and pass some value to it as follows:
GlobalVariables.getInstance().SetMyArrayList(someValue);
Now my question begins. The moment I press the button which is present inside the GridView, my button with a Dynamic Integer (which is on the left hand column outside) should increment its value. But I cannot increment it as I cannot access this button from inside the GridViewAdapter. Should I have an option to access that dynamic button from inside the GridViewAdapter, I will simply write the code:
button.setText(GlobalVariables.getInst开发者_Python百科ance().GetMyArrayList().size());
which will refresh this button and an updated value will be reflected over that button. Can anyone please help me out with this? I want to update the text on a button from inside a GridViewAdapter where the GridView and the Button both are present on the same activity but there are 2 separate java files - one for the activity and one for the GridViewAdapter.
Make GridViewAdapter an inner class of your activity class. Then it will have access to all fields of container class.
加载中,请稍侯......
精彩评论