It is necessary by clicking on the item in the ListView to change the Image (mark as viewed record). I use the following code:

lv.setOnItemClickListener(new OnItemClickListener() { for (int i = 0; i <= lv.getCount(); i++) { //.getAdapter().getCount() //.getCount(); if (position == i) { if (dbHandler.getDeliveredShipping(_id) == true) { ((ImageView) view.findViewById(R.id.subscriberVisited_image)).setImageResource(R.drawable.ic_check_all); } else if (dbHandler.getDeliveredShipping(_id) == false) { //http://stackoverflow.com/questions/21908022/change-image-of-imageview-onitemclicklistener-of-listview-in-android ((ImageView) view.findViewById(R.id.subscriberVisited_image)).setImageResource(R.drawable.ic_check); //lv.getChildAt(i).setBackgroundColor(Color.BLUE); } } } }); 

Clicking on one item picture (daw) changes also changes to the lower standing item (about 7 points to the bottom). Did debug, no hops to lower item. How does this happen?

a photo

Adapter:

  SimpleAdapter adapter; lv = getListView(); ArrayList<HashMap<String, String>> contactList; contactList = new ArrayList<HashMap<String, String>>(); protected void onPostExecute(Void result) { super.onPostExecute(result); // Dismiss the progress dialog if (pDialog.isShowing()) pDialog.dismiss(); /** * Updating parsed JSON data into ListView // * */ adapter = new SimpleAdapter( MainActivity.this, contactList, R.layout.list_item, new String[]{TAG_ID, TAG_SUBSCRIBER_NAME, TAG_NEWSPAPER_MNEMONIK_NAME, TAG_NUMBER_PUBLICATION, TAG_PHONE1}, new int[]{R.id.idShipping, R.id.subscriberName, R.id.newspaperName, R.id.newspaperPubNumber, R.id.subscriberTelNumber} ); setListAdapter(adapter); lv.setTextFilterEnabled(true); } 
  • Show the adapter code, it seems to me that you didn’t foresee the reuse of the cells there. - xkor
  • Thanks for the answer. How to understand did not provide for reuse of cells? - Arslanali
  • The topic of reusing items on the list has been discussed on this resource many times already; use the search to solve your problem - pavlofff
  • see, for example, this answer - pavlofff
  • Understood thanks. - Arslanali

1 answer 1

I'm afraid SimpleAdapter is not designed to be used with cells in which you also change the code yourself, the problem is that when a cell in which you change something scrolls behind the screen, it is reused to display the new cell that appears on the screen. At the same time, only the data for the views whose IDs you list in the array that you send with the last parameter to the SimpleAdapter constructor is changed. Thus, if you change something there yourself, these changes will also remain for the new cell. So you will have to either inherit from SimpleAdapter, or from BaseAdapter and implement the storage and application of changed states there.

  • Which adapter is suitable, or rather which one is better to use? - Arslanali
  • Well, if you inherit from SimpleAdapter, then I suppose you will have to add the least. - xkor
  • You mean to inherit main activity, it is inherited from me like this public class MainActivity extends ListActivity - Arslanali
  • I mean to create my own adapter class inherited from SimpleAdapter, implement in it what I described above and use it and not SimpleAdapter. - xkor