我设计了一个ListView子类,但我不知道是否最好从Fragment扩展并从onCreateView
或(如果可能)返回我的自定义ListView以让ListFragment处理它?
答案 0 :(得分:0)
覆盖onCreateView就是这样做的方法。
那说:
- 如果您提供自己的自定义ListView,为什么使用ListFragment?
- 您在ListView中包含哪些自定义?通常默认的ListView可以工作,而自定义则会进入ListAdapter。
答案 1 :(得分:0)
从Android SDK: Using Custom View In XML Based Layout提取的信息中,很容易回答您的问题:
在xml布局文件中,改为使用“ListView”,只需将名称(包含)放在xml文件中即可。一个例子:
<强>之前:强>
<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>
<强>后:强>
<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>