1
我使用DragSortListView庫。它工作正常 - 從我的列表視圖拖動和刪除項目,但我也想單擊ListView項目。當我設置OnClickListener時,它不起作用。可能是什麼問題呢?對不起,我的英語不好拖放分類列表查看項目點擊不起作用
我的片段:
private DragSortListView listView;
private MakeSingleBetAdapter adapter;
private View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
MyLog.d(TAG, "onCreateView");
BugSenseHandler.initAndStartSession(getActivity(), APP_Parameters.BugSense);
view = inflater.inflate(R.layout.fragment_make_single_bet,
container, false);
listView = (DragSortListView) view.findViewById(R.id.makeBetList);
listView.setRemoveListener(this);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(getActivity(), "Click: " + position, Toast.LENGTH_SHORT).show();
}
});
cursor = dbHelper.getAllBets();
adapter = new MakeSingleBetAdapter(getActivity(), cursor, 3, dbHelper);
listView.setAdapter(adapter);
return view;
}
@Override
public void remove(int which) {
Cursor cursorId = (Cursor) (listView.getItemAtPosition(which));
String id = cursorId.getString(cursor
.getColumnIndex(DBHelper.COL_BET_ID));
dbHelper.deleteBetById(id);
adapter.swapCursor(dbHelper.getAllBets());
}
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/ch.bettings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical" >
....
<com.mobeta.android.dslv.DragSortListView
android:id="@+id/makeBetList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/View1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:cacheColorHint="@color/slidingMenu"
android:divider="#b5b5b5"
app:drag_enabled="true"
app:drag_start_mode="onMove"
app:remove_enabled="true"
app:remove_mode="flingRemove"
app:sort_enabled="false" />
....
</RelativeLayout>
如果我在適配器添加ClickListener - 它工作的很好,但我不能拖列表項目
嘗試使用onClick而不是OnItemClick。 – Aashir
@Aashir E/AndroidRuntime(4833):java.lang.RuntimeException:不要爲AdapterView調用setOnClickListener。您可能希望setOnItemClickListener而不是 – WOLVERINE
嘗試將這些添加到您的列表視圖行:android:focusable =「false」 android:focusableInTouchMode =「false」 – Aashir