对于我的应用程序,我试图显示一个列表,一旦这个列表结束,第二个就会开始。列表正在使用 ListAdapter 显示,它又是片段的一部分。一切运行良好,列表显示正确,但我想不出一种方法将一个列表放在另一个列表之下。我认为这不应该太难。概括:
我所拥有的:
一个FragmentPagerAdapter
带有 3 个片段的两个片段,每个片段包含一个 ListView
我的搜索: 除了在这个网站上进行多次搜索外,这个人最接近我正在寻找的东西:这个人在Fragmentpageradapter 的 1 个选项卡中的 Fragmenttransaction遇到了同样的问题,但没有得到令人满意的回答,所以我想我可以在这里提出一个有效的问题。
我的问题:
我怎样才能将两个ListViews
放在一个片段中?重要的是,例如,如果第一个 ListView 比屏幕大,我不希望在第一个 ListView 完全向下滚动之前显示第二个 ListView。
当前输出:
目前,两者ListViews
都在同一位置,这意味着一个ListView
在另一个之上,使得两者都无法读取
我以为我可以为FragmentTransaction
. 但我就是不知道怎么做。
这是我结合顶部和底部的片段ListViews
public class LeaguePageTransactionsAdapter extends Fragment{
Global global_var;
ListView list, list_flat;
List <League> leagues = null, leaguesFlat = null;
ListAdapter adapter = null, adapter_flat = null;
View rootView;
FragmentTransaction fragmentTransaction;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.league_page, container, false);
fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(rootView.getId(), new LeaguePageTop(), "TopFragment");
fragmentTransaction.add(rootView.getId(), new LeaguePageBottom(), "BottomFragment");
fragmentTransaction.commit();
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
}
}
这是对应的xml布局文件。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
这是我的两个之一ListViews
public class LeaguePageTop extends Fragment{
ListView list;
List <League> leagues = null;
ListAdapter adapter = null;
View rootView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.league_page_top, container, false);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
list = (ListView) rootView.findViewById(R.id.listView1);
try {
leagues = Leagues_Parser.parse(getActivity().getAssets().open("league_raw.xml"), 0);
} catch (IOException e) {
e.printStackTrace();
}
adapter = new LeagueAdapter (getActivity(), R.layout.list_row, leagues);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Global.mViewPager.setCurrentItem(1, true);
}
});
}
}
这是对应的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>
非常感谢您阅读和思考!