问题
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