从活动的ArrayList传递给ListFragment? [英] Pass ArrayList from Activity to ListFragment?
问题描述
我想实现一个片段的布局。我有一个活动的服务器作为一个闪屏和放大器;从网上获取的一些数据,并创建我的自定义对象的ArrayList。
I am trying to implement a fragment layout. I have an activity that servers as a SplashScreen & fetches some data from the web and creates an ArrayList of my custom objects.
通常情况下如果我使用一个ListView我只想做好以下工作。
Normally If I were using a ListView I would just do the following.
private ArrayList<Articles> articles;
private void isComplete() {
Intent intent = new Intent(SplashScreen.this, ListActivity.class);
intent.putExtra("data", articles);
startActivity(intent);
finish();
}
我怎会传递相同的数据到一个片段?您的帮助,我更AP preciated。
How can I do pass the same data to a Fragment? Your help I much appreciated.
推荐答案
其简单采取全局类
和声明公共静态的ArrayList&LT;文章和GT;文章=新的ArrayList&LT;文章取代;
在主要活动 Global.articles =文章
;
现在ü可以使用任何地方的项目。
Its simple take Global class
And declare public static ArrayList<Articles> articles = new ArrayList<Articles>;
In main Activity Global.articles = articles
;
Now u can use any where in Project.
这篇关于从活动的ArrayList传递给ListFragment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!