拉刷新和loadmore列表视图,如Facebook [英] pull to refresh and loadmore listview like facebook
本文介绍了拉刷新和loadmore列表视图,如Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里我使用的滑动抽屉。在上点击主页图标它显示了3个标签
1)我应该申请标签这概念?
2)我想申请 pulltoreferesh
和 loadmore
在列表视图,如Facebook?
在你还看到,滚动起来的进度时,得到隐藏,并要求得到解除。
解决方案
公共类ListDemo扩展片段{
ArrayAdapter<字符串>文件;
私人链表<字符串> mListItems;
PullAndLoadListView LYT;
// ListView控件LV1;
//中的数据将被显示在ListView
私有String [] mNames = {法比安,卡洛斯,亚历克斯,安德烈,卡拉,
弗雷迪,拉扎罗,赫克托,州,埃德温,为Jhon
Edelmira,安德烈斯};
//中的数据将被显示在ListView
私有String [] mAnimals = {佩罗,小鲨鱼,Oveja,ELEFANTE,佩斯,
Nicuro,Bocachico,Chucha,居里,顿,阿吉拉,
莱昂,Jirafa};
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
捆绑savedInstanceState){
super.onCreateView(充气,容器,savedInstanceState);
最终的视图V = inflater.inflate(R.layout.tab_frag3_layout,集装箱,假);
mListItems =新的LinkedList<字符串>();
mListItems.addAll(Arrays.asList(mNames));
LYT =(PullAndLoadListView)v.findViewById(R.id.tab_frag3_listview1);
如果(集装箱== NULL){
返回null;
}
文件=新的ArrayAdapter<字符串>(getActivity(),android.R.layout.simple_list_item_1,mListItems);
lyt.setAdapter(文件);
lyt.setOnRefreshListener(新OnRefreshListener(){
@覆盖
公共无效onRefresh(){
// TODO自动生成方法存根
新PullToRefreshDataTask()执行()。
}
});
lyt.setOnLoadMoreListener(新OnLoadMoreListener(){
@覆盖
公共无效onLoadMore(){
// TODO自动生成方法存根
新LoadMoreDataTask()执行();
}
});
返回伏;
}
私有类LoadMoreDataTask扩展的AsyncTask<虚空,虚空,虚空> {
@覆盖
保护无效doInBackground(虚空...... PARAMS){
如果(isCancelled()){
返回null;
}
//模拟一个后台任务
尝试 {
视频下载(1000);
}赶上(InterruptedException异常E){
}
的for(int i = 0; I< mAnimals.length;我++)
mListItems.add(mAnimals [I]);
返回null;
}
@覆盖
保护无效onPostExecute(无效的结果){
mListItems.add(补充后装载更多);
//我们需要通知该数据已更改适配器
files.notifyDataSetChanged();
//调用onLoadMoreComplete当LoadMore任务,已完成
lyt.onLoadMoreComplete();
super.onPostExecute(结果);
}
@覆盖
保护无效onCancelled(){
//通知更多操作已完成的加载
lyt.onLoadMoreComplete();
}
}
私有类PullToRefreshDataTask扩展的AsyncTask<虚空,虚空,虚空> {
@覆盖
保护无效doInBackground(虚空...... PARAMS){
如果(isCancelled()){
返回null;
}
//模拟一个后台任务
尝试 {
视频下载(1000);
}赶上(InterruptedException异常E){
}
的for(int i = 0; I< mAnimals.length;我++)
mListItems.addFirst(mAnimals [I]);
返回null;
}
@覆盖
保护无效onPostExecute(无效的结果){
mListItems.addFirst(加拉刷新后);
//我们需要通知该数据已更改适配器
files.notifyDataSetChanged();
//调用onLoadMoreComplete当LoadMore任务,已完成
lyt.onRefreshComplete();
super.onPostExecute(结果);
}
@覆盖
保护无效onCancelled(){
//通知更多操作已完成的加载
lyt.onLoadMoreComplete();
}
}
}
这里是拉来刷新和负载更多的库。
here i am using sliding drawer. in that on click home icon it shows 3 tabs
1) which concept should i apply for tab ?
2) I want to apply pulltoreferesh
and loadmore
in listview like facebook ?
in that you have also seen that when scrolling up progressbar gets hide and request get cancel.
解决方案
public class ListDemo extends Fragment{
ArrayAdapter<String> files;
private LinkedList<String> mListItems;
PullAndLoadListView lyt ;
// ListView lv1;
// The data to be displayed in the ListView
private String[] mNames = { "Fabian", "Carlos", "Alex", "Andrea", "Karla",
"Freddy", "Lazaro", "Hector", "Carolina", "Edwin", "Jhon",
"Edelmira", "Andres" };
// The data to be displayed in the ListView
private String[] mAnimals = { "Perro", "Gato", "Oveja", "Elefante", "Pez",
"Nicuro", "Bocachico", "Chucha", "Curie", "Raton", "Aguila",
"Leon", "Jirafa" };
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
final View v = inflater.inflate(R.layout.tab_frag3_layout, container, false);
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mNames));
lyt = (PullAndLoadListView)v.findViewById(R.id.tab_frag3_listview1);
if (container == null) {
return null;
}
files = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,mListItems);
lyt.setAdapter(files);
lyt.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
// TODO Auto-generated method stub
new PullToRefreshDataTask().execute();
}
});
lyt.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
// TODO Auto-generated method stub
new LoadMoreDataTask().execute();
}
});
return v;
}
private class LoadMoreDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if (isCancelled()) {
return null;
}
// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
for (int i = 0; i < mAnimals.length; i++)
mListItems.add(mAnimals[i]);
return null;
}
@Override
protected void onPostExecute(Void result) {
mListItems.add("Added after load more");
// We need notify the adapter that the data have been changed
files.notifyDataSetChanged();
// Call onLoadMoreComplete when the LoadMore task, has finished
lyt.onLoadMoreComplete();
super.onPostExecute(result);
}
@Override
protected void onCancelled() {
// Notify the loading more operation has finished
lyt.onLoadMoreComplete();
}
}
private class PullToRefreshDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
if (isCancelled()) {
return null;
}
// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
for (int i = 0; i < mAnimals.length; i++)
mListItems.addFirst(mAnimals[i]);
return null;
}
@Override
protected void onPostExecute(Void result) {
mListItems.addFirst("Added after pull to refresh");
// We need notify the adapter that the data have been changed
files.notifyDataSetChanged();
// Call onLoadMoreComplete when the LoadMore task, has finished
lyt.onRefreshComplete();
super.onPostExecute(result);
}
@Override
protected void onCancelled() {
// Notify the loading more operation has finished
lyt.onLoadMoreComplete();
}
}
}
here is source code of pull-to-refresh and load-more library.
这篇关于拉刷新和loadmore列表视图,如Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文