Update EditText in a list view with value from a SeekBar

强颜欢笑 提交于 2019-12-08 08:54:10

问题


I have a ListView and each row item comprises of a SeekBar and an EditText (as in figure below). I need to update the EditText based on the seekbar's value, which I'm able to do if I have both the widget references without a problem.

My issue is how do I associate each seekbar to its correct EditText box? Both these widgets are part of a view that I inflate in my adapter. Referencing an EditText directly doesn't seem to be a good idea because of Android's view recycling in the ListView.

What is the best way forward?


回答1:


When you show each pair of SeekBar and editText just use

seekBar.setTag(editText);
editText.setTag(seekBar);

and when update something use

seekBar = (SeekBar)editText.getTag();
seekBar.setProgress(...);



回答2:


Change SeekBar progress based on EditText value

here was the same issue

Update SeekBar with EditText

here was the same issue too




回答3:


Set a OnSeekBarChangeListener to the SeekBar that change the TextView's text when OnProgressChanged() is called. Do this in the getView() in the Adapter.



来源:https://stackoverflow.com/questions/23802173/update-edittext-in-a-list-view-with-value-from-a-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!