我已经看过各种关于如何将Activity转换为ListActivity来填充ListView的教程,但是ListFragments却没有。我有两个标签,每个标签下都有一个片段。这是我的片段目前的样子....有人可以告诉我如何做到这一点吗?
public class MainFragment extends ListFragment {
String[] items = { "12 Monkeys", "(500) Days of Summer", "Chariots of Fire" };
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
这是XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
我试图让items
显示在ListView中。
答案 0 :(得分:3)
您无需在view
内部夸大listview
ListFragment
个adapter
。只需创建onCreate()
,在fragment
来电setListAdapter()
的{{1}}内提供一些数据。然后在其他地方(可能在您的Activity
中),您可以使用fragment
添加此fragmentmanager
。