分别设置listview加载中、空数据、加载数据失败

系统 1787 0
设置listview加载中,空数据,加载数据失败三种状态的显示.

分别设置listview加载中、空数据、加载数据失败三种状态的显示

分别设置listview加载中、空数据、加载数据失败三种状态的显示

分别设置listview加载中、空数据、加载数据失败三种状态的显示

基本用法:
    
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);
	}
}

  

分别设置listview加载中、空数据、加载数据失败三种状态的显示


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论