How to highlight ListView-Items
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) { for(int a = 0; a < parent.getChildCount(); a++) { parent.getChildAt(a).setBackgroundColor(Color.BLACK); } view.setBackgroundColor(Color.RED); }
In your Activity:
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long itemid) { itemOnclickList(position, view); } }); public void itemOnclickList(int position, View view) { if (listview.isItemChecked(position)) { view.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_checked)); } else { view.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_uncheck)); } adapter.notifyDataSetChanged();}
In your Adapter:
public View getView(int position, View view, ViewGroup parent) { View convertView = inflater.inflate(R.layout.listdocument_item, null); ListView lvDocument = (ListView) parent; if (lvDocument.isItemChecked(position)) { convertView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.image_checked)); } else { convertView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.image_uncheck)); } return convertView;}
Good luck!