对于我的应用程序,我试图显示一个列表,一旦这个列表结束,第二个应该开始。列表正在使用ListAdapter显示,该列表又是片段的一部分。一切正常,列表显示正确,但我无法想出一种方法将一个列表放在另一个列表下。我认为这不应该太难。 摘要:Android:使用FragmentTransaction通过片段显示两个ListViews
我有什么: 一个FragmentPagerAdapter
有3个片段 两个片段,其中包含一个ListView的每个
我的搜索: 除了对本网站的多个搜索,这家伙是最接近我正在寻找: 这个人在这里Fragmenttransaction in 1 tab of a Fragmentpageradapter也有同样的问题,但没有得到满意的答复,所以我想我可以在这里提出一个有效的问题。
我的问题: 如何将两个ListViews
放置在一个片段中?重要的是,例如,如果第一个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>
非常感谢您阅读和思考!
我刚试过你的解决方案,不幸的是它没有工作。我认为这是因为首先'ListView'已经占用了所有可用的屏幕空间,而且我无法用'FragmentTransaction'指定更多的布局设置:\ 不过谢谢您的回复! – Guntram