int pos = 0;
int save = -1;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Always set the item clicked blue background
view.setBackgroundColor(Color.BLUE);
if (pos == 0) {
if (save != -1) {
parent.getChildAt(save).setBackgroundColor(Color.BLACK);
}
save = position;
pos++;
Log.d("Pos = 0", "Running");
} else {
parent.getChildAt(save).setBackgroundColor(Color.BLACK);
save = position;
pos = 0;
Log.d("Pos # 0", "Running");
}
private static int save = -1;
public void onListItemClick(ListView parent, View v, int position, long id) {
parent.getChildAt(position).setBackgroundColor(Color.BLUE);
if (save != -1 && save != position){
parent.getChildAt(save).setBackgroundColor(Color.BLACK);
}
save = position;
}
if (!Model.Read)
rowItemContainer.SetBackgroundColor (Android.Graphics.Color.ParseColor ("#FFFDD0")); // unread color
else
rowItemContainer.SetBackgroundColor (Android.Graphics.Color.White); // read color
final List<String> fruits_list = new ArrayList<String>(Arrays.asList(fruits));
// Create an ArrayAdapter from List
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, fruits_list){
@Override
public View getView(int position, View convertView, ViewGroup parent){
// Get the current item from ListView
View view = super.getView(position,convertView,parent);
if(position %2 == 1)
{
// Set a background color for ListView regular row/item
view.setBackgroundColor(Color.parseColor("#FFB6B546"));
}
else
{
// Set the background color for alternate row/item
view.setBackgroundColor(Color.parseColor("#FFCCCB4C"));
}
return view;
}
};
// DataBind ListView with items from ArrayAdapter
lv.setAdapter(arrayAdapter);
}