Is it possible to customize a custom ListView in a ListFragment?

I developed a subclass of ListView, but I don't know if it is better to extend it from Fragment and return your own custom ListView from onCreateView

or (if possible) to let the ListFragment handle it?

+3


source to share


2 answers


overriding onCreateView would be the way to do it.



That said:
-If you supply your own ListView, why are you using ListFragment?
-What settings do you include in your ListView? Often the default ListView works, and the settings are listed.

0


source


From information pulled from Android SDK: Using a custom view in XML layout , it is easy to answer your question:

In your layout xml file, instead of using "ListView" just put the name (with packages) in the xml file. Example:

Before:



 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

     <ListView android:id="@id/android:list"
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:background="@color/list_background"
               android:layout_weight="1" />

     <TextView android:id="@id/android:empty"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="@color/no_data_list_background"
               android:text="No data" />
 </LinearLayout>

      

After:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

     <com.mycompany.BounceListView android:id="@id/android:list"
               android:layout_width="match_parent"
               android:layout_height="0dp"
               android:background="@color/list_background"
               android:layout_weight="1" />

     <TextView android:id="@id/android:empty"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="@color/no_data_list_background"
               android:text="No data" />
 </LinearLayout>

      

0


source







All Articles