To do Android development for two years, the technology has a little upgrade, just the function of their realization to write out, record, if you can help other people in the peer, I have done a good thing, haha!! No more nonsense, just the last picture.
First the previous code:
1 if (lastposition = = position) {
2 viewholder.setimageresource (r.id.iv_yuandian1,r.mipmap.ic_button_ checked);
3 } else {
4 viewholder.setimageresource (r.id.iv_yuandian1,r.mipmap.ic_button_unchecked);
5 }
I first record the default position in the adapter, because I built a listviewadapter abstract class in the project, so each time I use it, I just need to make a new one in the activity, and then set the text content or picture resources directly in the method ( As the above code to write), will share with you this abstract class, of course, this abstract class or under the guidance of the master to complete, we can ignore this writing, according to the normal baseadapter written on the line. Pull it off, say back to the subject. In fact, the main part of the entire feature in the ListView item click event, its main code is as follows:
Lv_choosecompany.setonitemclicklistener (New Adapterview.onitemclicklistener () {
@Override public
Void Onitemclick (adapterview<?> adapterview, view view, int position, long L) {
//Select the currently selected entry with the selected effect
old_ ImageView = (ImageView) View.findviewbyid (r.id.iv_yuandian1);
Old_imageview.setimageresource (r.mipmap.ic_button_checked);
New_imageview = (ImageView) View.findviewbyid (r.id.iv_yuandian1);
if (lastposition!=-1 && lastposition!= position) {
//If the entry has already been clicked and the last saved item position differs from the current position
New_ Imageview.setimageresource (r.mipmap.ic_button_unchecked)//Remove the last selected style
}
New_imageview = Old_imageview //Save the current entry
lastposition = position;//Save the current position
listviewadapter.notifydatasetchanged ();
}
);
The whole process is almost like this, if you want to retain the selected text information, only need to click on the time, will be the content of the TextView to save, here is not the display code, the lack of places to ask the colleagues a lot of advice.
Thank you for reading, I hope to help you, thank you for your support for this site!