【发布时间】:2015-11-09 17:11:42
【问题描述】:
我的 MainActivity 有两个片段(Tab1 和 Tab2)。 我已经通过 XML 解析 2 次从 URL 获取数据,并存储在 MainActivity 的 2 个不同的 ArrayList 中。
这两个片段有列表视图。现在我必须将 1 个 Arraylist 传递给一个片段,并将第 2 个 ArrayList 传递给第二个片段,然后将这些 ArrayList 显示到这两个片段的 ListViews 中。
我如何将 2 个 Arraylists 传递给这两个片段,以及如何在这两个片段中显示它们。
这是 MinActivity 的 onCreate 方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadPage();
// Creating The Toolbar and setting it as the Toolbar for the activity
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
}
我在另一个函数(OnPostExecute)中有两个 ArrayList,我通过 XML 解析接收数据。
我没有在两个片段中编辑任何内容。到目前为止,我只是用列表视图创建了这两个片段
【问题讨论】:
标签: java android android-fragments arraylist