简体   繁体   English

ListView中每行的颜色不同,我也想拖动该行,并且每行的背景颜色也要交换。 怎么做

[英]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. 我为ListView每一行设置了不同的颜色,我想Drag and Drop每一行与相应的背景色一起Drag and Drop

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;
        }

Experience - Android Drag and Drop List 体验-Android拖放列表

Drag and drop list view on Android 在Android上拖放列表视图

Above is the complete tutorials for what you are looking for . 以上是您正在寻找的完整教程。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM