particular list item select to set bgcolor for list item ,when scroll down listview to automatically set color for other item, my sample code suggestion and help me.(this code v.setbackgroundcolor(Color.gray)
using problem occur,so clear the problem)
public class MainActivity extends Activity {
ListView list;
ArrayAdapter<String> adapter;
ArrayList<String>listitem=new ArrayList<String>();
String val;
String[] list_number={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list=(ListView)findViewById(R.id.listView1);
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list_number);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
String selectedFromList =(list.getItemAtPosition(position).toString());
if(listitem.isEmpty())
{
listitem.add(selectedFromList);
Set<String> primesWithoutDuplicates = new LinkedHashSet<String>(listitem);
listitem.clear();
listitem.addAll(primesWithoutDuplicates);
v.setBackgroundColor(Color.GRAY);
}
else
{
if( listitem.contains(selectedFromList))
{
listitem.remove(selectedFromList);
v.setBackgroundColor(Color.WHITE);
}
else
{
listitem.add(selectedFromList);
Set<String> primesWithoutDuplicates = new LinkedHashSet<String>(listitem);
listitem.clear();
listitem.addAll(primesWithoutDuplicates);
v.setBackgroundColor(Color.GRAY);
}
}
}
});
}
}