使用这个例子,这有点复杂 https://github.com/philcbrown/DraggableListView 我试图禁用特定项目点击/触摸移动到特定pos并检查特定文本,一个接一个的所有listview项目,但它没有工作,我尝试使用
mylist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int pos, long id) {
// TODO Auto-generated method stub
TextView c = (TextView) view.findViewById(R.id.textView1);
String playerChanged = c.getText().toString();
Log.d("1", ""+"Item clicklistener");
if (pos == 0) {
if (playerChanged == "King")
Log.d("2", ""+"in isEnabled");
mDraggableListView.setDragStatus(false);
} else {
mDraggableListView.setDragStatus(true);
}
}
});
在设置了listview适配器的类中,也是
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
if (position == 1){
if (text == "King")
Log.d("3", ""+"in isEnabled");
return true;
}
return false;
}
在DraggableGenericAdapter类中,首次使用listview
我的getView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
boolean isConverted = true;
if (view == null) {
Log.v("talkinginterval", "create view " + position);
view = mInflater.inflate(mViewResourceId, parent, false);
isConverted = false;
}
modifyView(position, view, isConverted);
for (int i = 0; i < mTo.length; i++) {
View v = view.findViewById(mTo[i]);
String from = mFrom[i];
String data = mDataProvider.getItem(position);
String d = data.toString();
boolean bound = false;
if (mViewBinder != null) {
bound = mViewBinder.setViewValue(view, v, d, from);
}
if (!bound) {
if (v instanceof TextView) {
((TextView) v).setText(d);
} else {
throw new IllegalStateException(v.getClass().getName() + " is not a "
+ " view that can be bounds by this Adapter");
}
}
}
return view;
}
和布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mk="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" />
<RelativeLayout
android:layout_width="960dp"
android:layout_height="540dp"
android:layout_centerInParent="true">
<com.package.DraggableListView
android:id="@+id/listView1"
android:layout_width="894dp"
android:layout_height="420dp"
android:background="#ffffff"
android:layout_marginTop="90dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp" />
</RelativeLayout>
</RelativeLayout>
and
<?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:layout_gravity="center"
android:minHeight="60dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textStyle="bold"
android:textSize="30dp"
android:gravity="center"
android:text="TextView" />
</RelativeLayout>