cihm cihm - 28 days ago 9
Android Question

Different color for each row in a ListView, I want to drag the row and each row's background color exchange too. how to do it

I set a different color for each row in a

ListView
and I want to
Drag and Drop
each row along with the corresponding background color.

the way to set different row background is showing below, now I want to drag row to change with other row and each row's background must be exchange too

public static class DragListAdapter extends ArrayAdapter<String>{

public DragListAdapter(Context context, List<String> objects) {
super(context, 0, objects);
}
public List<String> getList(){
return list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = convertView;

view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item, null);

TextView textView = (TextView)view.findViewById(R.id.drag_list_item_text);
textView.setText(getItem(position));

switch(position){
case 0:
textView.setBackgroundResource(R.drawable.gray);
break;
case 1:
textView.setBackgroundResource(R.drawable.white);
break;
case 2:
textView.setBackgroundResource(R.drawable.Pink);
break;
case 3:
textView.setBackgroundResource(R.drawable.Cyan);
break;
case 4:
textView.setBackgroundResource(R.drawable.Gainsboro);
break;
case 5:
textView.setBackgroundResource(R.drawable.Magenta);
break;
case 6:
textView.setBackgroundResource(R.drawable.MediumSpringGreen);
break;
case 7:
textView.setBackgroundResource(R.drawable.SteelBlue);
break;
case 8:
textView.setBackgroundResource(R.drawable.Yellow);
break;
case 9:
textView.setBackgroundResource(R.drawable.LightSteelBlue);
break;

}
return view;
}

Answer Source

Experience - Android Drag and Drop List

Drag and drop list view on Android

Above is the complete tutorials for what you are looking for . Thanks