向Drag-Sort-Listview库添加单击侦听器

时间:2014-11-13 14:50:02

标签: java android listview android-listfragment

我已经基于listfragment实现了这个库,它的实现与库的github repo上的代码示例非常相似:

https://github.com/bauerca/drag-sort-listview/blob/master/demo/src/com/mobeta/android/demodslv/DSLVFragment.java

我的问题是,如何实现点击监听器?

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<com.mobeta.android.dslv.DragSortListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dslv="http://schemas.android.com/apk/lib/com.mobeta.android.dslv"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="3dp"
    dslv:drag_handle_id="@drawable/bg_handle"
    android:layout_margin="3dp"
    android:dividerHeight="2dp"
    dslv:drag_enabled="true"
    dslv:collapsed_height="2dp"
    dslv:drag_scroll_start="0.33"
    dslv:max_drag_scroll_speed="0.5"
    dslv:float_alpha="0.6"
    dslv:slide_shuffle_speed="0.3"
    dslv:track_drag_sort="false"
    dslv:float_background_color="@color/blue"
    android:focusable="false"
    android:focusableInTouchMode="false"
    dslv:use_default_controller="false" />

这就是我尝试创建点击监听器的方式,但它没有回复:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDslv = (DragSortListView) inflater.inflate(getLayout(), container, false);

mController = buildController(mDslv);
mDslv.setFloatViewManager(mController);
mDslv.setOnTouchListener(mController);
mDslv.setDragEnabled(dragEnabled);


SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(mDslv);
simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
mDslv.setFloatViewManager(simpleFloatViewManager);

mDslv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        System.out.println("Clicked!");
    }
});


return mDslv;

}

1 个答案:

答案 0 :(得分:1)

这是因为您同时使用OnItemClickListenerOnTouchListener 您有 3个选项,只需选择您喜欢的选项:
1)放弃OnTouchListener
2)当您需要点击生成时,从onTouch()返回false 3)必要时在mDslv.performClick()生成点击自己onTouch()