我知道,这个问题已经回答了,我也知道解决简单的问题。只需将android:id="@android:id/list"
添加到ListView。但是我遇到的问题有点不同。我的问题differns在以下几个方面:多列表视图:您的内容必须有一个ListView其id属性为“android.R.id.list”
1:我使用了一个片段
2:我想使用多个列表视图 3:我有自定义阵列适配器
我有一个LinearLayout
包含两个其他LinearLayout
。他们每人持有另一ListView
。简而言之,我想在我的布局中使用两种不同的ListViews
。现在的问题是,我希望他们都工作。我会怎么做?
//LinearLayoutStart
//Some code
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="@+id/tv_openGames"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offene Spiele"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<ListView
android:id="@+id/lv_openGames"
android:layout_width="fill_parent"
android:layout_height="120dp" >
</ListView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="@+id/tv_openChallenges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offene Herausforderungen"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<ListView
android:id="@+id/lv_openChallenges"
android:layout_width="fill_parent"
android:layout_height="170dp" >
</ListView>
</LinearLayout>
//LinearLayoutEnd
所以,现在在我的Java代码我做到以下几点:
private ChallengeListAdapter adapterListChallenges;
private ArrayList<Challenge> arrayListChallenges = new ArrayList<Challenge>();
private GameListAdapter adapterListGames;
private ArrayList<Game> arrayListGames = new ArrayList<Game>();
private ListView lvOpenGames;
private ListView lvOpenChallenges;
lvOpenChallenges = (ListView) view.findViewById (R.id.lv_openChallenges);
lvOpenGames = (ListView) view.findViewById (R.id.lv_openGames);
adapterListChallenges = new ChallengeListAdapter(getActivity().getApplicationContext(), arrayListChallenges);
adapterListGames = new GameListAdapter(getActivity().getApplicationContext(), arrayListGames);
lvOpenChallenges.setAdapter (adapterListChallenges);
lvOpenGames .setAdapter (adapterListGames);
当我只使用一个ListView
和一个适配器,它工作得很好,因为我可以只给ListView
之一编号为android:list
,然后拨打setListAdapter
。但现在,我也在一个片段。那么,我将如何去与此?
但是也正是这个问题你有吗?你尝试了什么?你使用的是片段还是ListFragment? – fasteque
我正在使用'ListFragment'。问题是,我不知道如何处理它,当我有两个'ListView's。我知道,当我只有一个'ListView'时,如何处理这个错误,但是当我有两个时,我该怎么做呢?我的意思是,当我调用'setListAdapter'时,我无法告诉应用程序使用两个ListView中的哪一个,对吗? – Musterknabe
你必须使用一个片段,而不是一个ListFragment,所以你可以管理你想分开的所有列表视图。 ListFragment是一个有用的类,它为你做了一些工作,但它只需要一个listview。 – fasteque