Reputation: 299
I'm trying to implement this dynamicListView from DevBytes inside a ListFragment.
source: http://developer.android.com/shareables/devbytes/ListViewDraggingAnimation.zip
I'm doing this by creating a simple layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.android.listviewdragginganimation.DynamicListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
and inflating this layout in my ListFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
inflater.inflate(R.layout.simple_list_layout, container);
return super.onCreateView(inflater, container, savedInstanceState);
}
The DynamicListView seems to have initialized correctly (it's init(Context) function is run). But it's just working as if it was just a normal ListView. i.e. items are all displayed and I can scroll up and down, but the DynamicListViews onItemLongClickListener never gets called.
Is there anything else that needs to be done to use a custom ListView in a ListFragment?
Upvotes: 0
Views: 549
Reputation: 3030
You are inflating your custom layout but returning the default one. Change your code to
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.simple_list_layout, container);
}
After that you can call getListView().setOnLongClickListener(myClickListener)
as normal.
Edit: Add a second view inside your layout with the id android:id="@id/android:empty"
for a bonus empty-state.
Upvotes: 2