の各行に異なる色を設定し、各行に対応する背景色を付けListView
たいと思います。Drag and Drop
別の行の背景を設定する方法を以下に示します。行をドラッグして他の行と変更したいので、各行の背景も交換する必要があります
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;
}