80,490
社区成员
发帖
与我相关
我的任务
分享

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(groupKey.contains(getItem(position)) ){
//如果是分组标签,就加载分组标签的布局文件,两个布局文件显示效果不同
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_tag, null);
}else{
pos = position % 10;
switch (pos)
{
case 1:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_red, null);
break;
case 2:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_yellow, null);
break;
case 3:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_green, null);
break;
case 4:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_blue, null);
break;
case 5:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_darkblue, null);
break;
case 6:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_purple, null);
break;
case 7:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_orange, null);
break;
case 8:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_midnightblue, null);
break;
case 9:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_pink, null);
break;
case 0:
view = LayoutInflater.from(getContext()).inflate(R.layout.drag_list_item_white, null);
break;
}
}
TextView textView = (TextView)view.findViewById(R.id.drag_list_item_text);
textView.setText(getItem(position));
return view;
}<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffff00">
<TextView
android:id="@+id/drag_list_item_text"
android:layout_width="wrap_content"
android:layout_height="@dimen/drag_item_normal_height"
android:paddingLeft="5dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"/>
<ImageView android:id="@+id/drag_list_item_image"
android:src="@drawable/list_icon"
android:layout_width="wrap_content"
android:layout_height="@dimen/drag_item_normal_height"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff" />
</RelativeLayout>public void onDrop(int y){
//为了避免滑动到分割线的时候,返回-1的问题
int tempPosition = pointToPosition(0, y);
if(tempPosition != INVALID_POSITION){
dragPosition = tempPosition;
}
//超出边界处理
if(y < getChildAt(1).getTop()){
//超出上边界
dragPosition = 1;
}else if(y > getChildAt(getChildCount()-1).getBottom()){
//超出下边界
dragPosition = getAdapter().getCount()-1;
}
//数据交换
if(dragPosition > 1 && dragPosition < getAdapter().getCount()){
@SuppressWarnings("unchecked")
DragListActivity.DragListAdapter adapter = (DragListActivity.DragListAdapter)getAdapter();
String dragItem = adapter.getItem(dragSrcPosition);
adapter.remove(dragItem);
adapter.insert(dragItem, dragPosition);
自己觉得应该要改写在这...............却不知要如何改写
}
}