0

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?

1
  • u need to override onItemLongClickListener in your fragment Commented Dec 19, 2014 at 7:11

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.