我在这里使用滑动抽屉。在点击主页图标时,它显示 3 个标签
1) 我应该为标签申请哪个概念?
2)我想申请pulltoreferesh
并loadmore
在像facebook这样的列表视图中?因为您还看到,当向上滚动时,进度条会隐藏并请求取消。
问问题
8837 次
3 回答
4
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.
于 2013-03-16T09:26:43.217 回答
3
使用这个库,我几天前使用过并且工作完美:
于 2013-05-30T18:38:53.903 回答
1
我自己没有使用过这个库,它已经停产(2 个月前),但它看起来很棒,有例子和所有:
https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide
从我读到的,基本上你需要用库的列表视图替换你自己的列表视图并导入 jar 文件,你很高兴;-)
于 2013-03-13T11:25:40.750 回答