分别设置listview加载中、空数据、加载数据失败三种状态的显示
2014-11-24 21:35
363 查看
转载地址:http://gundumw100.iteye.com/blog/2009493
设置listview加载中,空数据,加载数据失败三种状态的显示.
基本用法:
Java代码
import java.util.ArrayList;
import java.util.Arrays;
import com.kanak.emptylayout.EmptyLayout;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.app.ListActivity;
public class MainActivity extends ListActivity {
private EmptyLayout mEmptyLayout; // this is required to show different layouts (loading or empty or error)
private ArrayAdapter<String> mAdapter;
private View.OnClickListener mErrorClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Try again button clicked", Toast.LENGTH_LONG).show();
}
};
// the list items
static final String[] MOVIES = new String[] {
"Forrest Gump",
"Toy Story",
"Saving Private Ryan",
"Toy Story 2",
"The Green Mile",
"Cast Away",
"Road to Perdition",
"Catch Me If You Can",
"The Terminal",
"The Polar Express",
"The Da Vinci Code",
"Angels & Demons",
"Toy Story 3",
"Extremely Loud & Incredibly Close",
"Cloud Atlas",
"Captain Phillips",
"Toy Story 4",
"The Lost Symbol"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize the empty view
mEmptyLayout = new EmptyLayout(this, getListView());
mEmptyLayout.setErrorButtonClickListener(mErrorClickListener);
// populate the list view
populateList();
}
// Triggered when "Empty" button is clicked
public void onShowEmpty(View view) {
// clear the list and show the empty layout
mAdapter.clear();
mEmptyLayout.showEmpty();
}
// Triggered when "Loading" button is clicked
public void onShowLoading(View view) {
// clear the list and show the loading layout
mAdapter.clear();
mEmptyLayout.showLoading();
}
// Triggered when "Error" button is clicked
public void onShowError(View view) {
// clear the list and show the error layout
mAdapter.clear();
mEmptyLayout.showError();
}
// Triggered when "List" button is clicked
public void onShowList(View view) {
// show the list
populateList();
}
private void populateList() {
ArrayList<String> list = new ArrayList<String>();
list.addAll(Arrays.asList(MOVIES));
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
setListAdapter(mAdapter);
}
}
Android-Empty-Layout-master.zip (2.5 MB)
下载次数: 62
设置listview加载中,空数据,加载数据失败三种状态的显示.
基本用法:
Java代码
import java.util.ArrayList;
import java.util.Arrays;
import com.kanak.emptylayout.EmptyLayout;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.app.ListActivity;
public class MainActivity extends ListActivity {
private EmptyLayout mEmptyLayout; // this is required to show different layouts (loading or empty or error)
private ArrayAdapter<String> mAdapter;
private View.OnClickListener mErrorClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Try again button clicked", Toast.LENGTH_LONG).show();
}
};
// the list items
static final String[] MOVIES = new String[] {
"Forrest Gump",
"Toy Story",
"Saving Private Ryan",
"Toy Story 2",
"The Green Mile",
"Cast Away",
"Road to Perdition",
"Catch Me If You Can",
"The Terminal",
"The Polar Express",
"The Da Vinci Code",
"Angels & Demons",
"Toy Story 3",
"Extremely Loud & Incredibly Close",
"Cloud Atlas",
"Captain Phillips",
"Toy Story 4",
"The Lost Symbol"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize the empty view
mEmptyLayout = new EmptyLayout(this, getListView());
mEmptyLayout.setErrorButtonClickListener(mErrorClickListener);
// populate the list view
populateList();
}
// Triggered when "Empty" button is clicked
public void onShowEmpty(View view) {
// clear the list and show the empty layout
mAdapter.clear();
mEmptyLayout.showEmpty();
}
// Triggered when "Loading" button is clicked
public void onShowLoading(View view) {
// clear the list and show the loading layout
mAdapter.clear();
mEmptyLayout.showLoading();
}
// Triggered when "Error" button is clicked
public void onShowError(View view) {
// clear the list and show the error layout
mAdapter.clear();
mEmptyLayout.showError();
}
// Triggered when "List" button is clicked
public void onShowList(View view) {
// show the list
populateList();
}
private void populateList() {
ArrayList<String> list = new ArrayList<String>();
list.addAll(Arrays.asList(MOVIES));
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
setListAdapter(mAdapter);
}
}
Android-Empty-Layout-master.zip (2.5 MB)
下载次数: 62
相关文章推荐
- 分别设置listview加载中、空数据、加载数据失败三种状态的显示
- 判断网络状态 fragment隐藏显示 xlistview多条目加载数据
- flex 加载图片失败,设置默认显示图片
- Android学习笔记_37_ListView批量加载数据和页脚设置
- easyUI-datagrid属性设置display:none,加载数据或表头不显示
- android快速开发框架--快速实现 页面 加载中 加载失败 无数据等状态以及下拉刷新和自动加载
- ListView 数据加载 +数据读取+ 数据格网状显示+判断数据是否重复
- Android ListView数据绑定显示的三种解决方法
- android studio编程时出现的错误:ListView重新载入后,更新数据或者再次进入该ListView加载数据,数据不显示 解决方法
- Android数据缓存加载,listview显示
- (小笔记)popupwindow中listview加载的网络数据有时显示有时不显示
- 点击加载更多(适用于listview在scrollview单行显示修正后多数据加载慢的情况)
- 【Android】提升用户体验,ListView显示加载中动画及空数据视图
- ListView加载list集合中数据从后到前显示问题
- Andoid 采用ListView三种显示数据列表
- Android学习笔记_37_ListView批量加载数据和页脚设置
- 一起学android之设置ListView数据显示的动画效果(24)
- ListView无数据,显示点击加载等友好界面
- MFC-窗口-显示状态设置的三种方法
- 五种情况下会刷新控件状态(刷新所有子FWinControls的显示)——从DFM读取数据时、新增加子控件时、重新创建当前控件的句柄时、设置父控件时、显示状态被改变时