对不起,我的英语不好。在我加载所有数据之前,如果用户进入应用程序,我使用isynk任务。但现在我需要使用惰性加载(例如:instagram),如果我没有互联网,我可以看到最后一篇文章(图像,文本)。如果我下拉列表,加载新数据。我不明白这是怎么做的。这是我现在的结构项目:
//this i load json
ArrayList<NewsObject> newsList;
ListView list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//code
list = (ListView) findViewById(R.id.list);
newsList = new ArrayList<NewsObject>();
//code
//load data(json)
new NewsAsynkTask().execute();
}
public class NewsAsynkTask extends AsyncTask<String , Void, String> {
//code
protected String doInBackground(String... params) {
//this i add json to object,
//then i add in list object
newsList.add(newsObject);
}
protected void onPostExecute(String file_url) {
//adapter in game
NewsAdapter adapter = new NewsAdapter(getApplicationContext(), R.layout.n_news_list_object, newsList);
list.setAdapter(adapter);
}
} 然后适配器显示全部。我看到了示例,但我不能理解如何获得json,然后添加惰性加载。请给我讲解或简单的一课
发布于 2015-04-25 18:45:24
在这里,您必须缓存以前加载的结果(NewsList)。在打开应用程序时,你会从缓存中获取NewsList (这样会更快),然后你就可以从服务(instagram)中寻找新的更新。
有关拉取时的更新,请查看此教程http://www.tutecentral.com/android-pull-to-refresh/
https://stackoverflow.com/questions/29864021
复制相似问题