Reputation: 561
I've implemented this library based off a listfragment, and its implementation is very similar to this code sample on the library's github repo:
My question is, how do I implement a click listener?
This is my xml file:
<?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" />
And this is how I've tried to create a click listener, but it doesn't respond:
@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;
}
Upvotes: 0
Views: 545
Reputation: 3296
It is because you use at the same time OnItemClickListener
and OnTouchListener
.
You have 3 options, just choose one you like:
1) Give up OnTouchListener
2) Return false from onTouch()
when you need click to be generated
3) Generate click yourself mDslv.performClick()
in onTouch()
when required
Upvotes: 1