2

我为 a 中的每一行设置了不同的颜色,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;
        }
4

1 回答 1

1

体验——安卓拖拽列表

Android 上的拖放列表视图

以上是您正在寻找的完整教程。谢谢

于 2012-07-14T15:57:06.787 回答