Change button text inside ListView in Android

I have a custom ListView with a custom ArrayAdapter. One row consists of 10 buttons. I cannot change the title of the buttons after clicking the button. Inside the getView method, I collect a holder for all of my buttons. The click listener is in the main action, it works correctly (I think so), I can get a link to the button:

MyHolder h = (MyHolder) getListView().getAdapter().getView(position, null, null).getTag();

Button b = h.myButton;

now when i call b.getText () it gives me the text with the button pressed. But when I try: b.setText ("xxx"); button text does not change.

any ideas?

+4
source share
1 answer

I don't think calling: getListView().getAdapter().getView(position, null, null) manually actually returns the existing View to position . This only creates a new view with the same data, so you do not see any changes and do not get any errors.

Just use the View passed to Button OnClickListener to change your own text.

 public void onClick(View v) { Button b = (Button) v; b.setText(...); } 
+3
source

Source: https://habr.com/ru/post/1445245/


All Articles