Pagerstwich tab样式加下拉刷新(三)

例子和上面的两个是同一个,这次主要是activity的代码

这段代码主要实现每个list_item格式相同,不同的有点不一样

public class MyOrderActivity extends BaseActivity implements PagerSwitchListener, ErrorClickListener ,OnPageChangeListener , IXListViewListener{

	@InjectView(id = R.id.back1)
	private ImageButton back;
	
	@InjectView(id = R.id.pagerSwitch)
	private PagerSwitch pagerSwitch;
	
	private String[] titleNames = new String[]{"待付款" , "已付款" , "待评价" ,"待接收"};
	private int[] pages = new int[]{1,1,1,1};
	
	@InjectView(id = R.id.myorder_viewpager)
	private ViewPager myorder_viewpager;
	
	private List<View> pager;
	private List<XListView> lists;
	private List<LoadView> loadViews;
	private List<MyorderAdapter> adapters;
	
	
	private List<MyorderInfo> firstList;
	private List<MyorderInfo> secondList;
	private List<MyorderInfo> thirdList;
	private List<MyorderInfo> fourList;      //前面model好像粘贴错了,,,懂就好,,,一点点差别
	
	private int testNum = 1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_order);
		pagerSwitch.init(titleNames);
		pagerSwitch.setSelect(0);
		pagerSwitch.setPagerSwitchListener(this);
		
		initPager();                                        
		loadListFromLoadView(0);
		loadListFromLoadView(1);
		loadListFromLoadView(2);
		loadListFromLoadView(3);
	}
	private void initPager() {
		// TODO Auto-generated method stub
		pager = new ArrayList<View>(4);
		lists = new ArrayList<XListView>(4);
		loadViews = new ArrayList<LoadView>(4);
		adapters = new ArrayList<MyorderAdapter>(3);
		
		firstList = new ArrayList<MyorderInfo>();
		secondList = new ArrayList<MyorderInfo>();
		thirdList = new ArrayList<MyorderInfo>();
		fourList = new ArrayList<MyorderInfo>();
		
		View pager1 = LayoutInflater.from(this).inflate(R.layout.common_list, null);
		XListView list1 = (XListView)pager1.findViewById(R.id.xlistView);
		LoadView loadView1 = (LoadView)pager1.findViewById(R.id.loadView);
		loadView1.setErrorClickListener(this);                                          //public Interface ErrorClicklistener{
		MyorderAdapter adapters1 = new MyorderAdapter(this,firstList);                  //     public reload(int type);                           
		list1.setAdapter(adapters1, 0);                                                 //}
		list1.setXListViewListener(this);
		lists.add(list1);
		loadViews.add(loadView1);
		adapters.add(adapters1);
		pager.add(pager1);
		
		View pager2 = LayoutInflater.from(this).inflate(R.layout.common_list, null);
		XListView list2 = (XListView)pager2.findViewById(R.id.xlistView);
		LoadView loadView2 = (LoadView)pager2.findViewById(R.id.loadView);
		loadView2.setErrorClickListener(this);
		MyorderAdapter adapters2 = new MyorderAdapter(this,secondList);
		list2.setAdapter(adapters2, 1);
		list2.setXListViewListener(this);
		lists.add(list2);
		loadViews.add(loadView2);
		adapters.add(adapters2);
		pager.add(pager2);
		
		View pager3 = LayoutInflater.from(this).inflate(R.layout.common_list, null);
		XListView list3 = (XListView)pager3.findViewById(R.id.xlistView);
		LoadView loadView3 = (LoadView)pager3.findViewById(R.id.loadView);
		loadView3.setErrorClickListener(this);
		MyorderAdapter adapters3 = new MyorderAdapter(this,thirdList);
		list3.setAdapter(adapters3, 2);
		list3.setXListViewListener(this);
		lists.add(list3);
		loadViews.add(loadView3);
		adapters.add(adapters3);
		pager.add(pager3);
		
		View pager4 = LayoutInflater.from(this).inflate(R.layout.common_list, null);
		XListView list4 = (XListView)pager4.findViewById(R.id.xlistView);
		LoadView loadView4 = (LoadView)pager4.findViewById(R.id.loadView);
		loadView4.setErrorClickListener(this);
		MyorderAdapter adapters4 = new MyorderAdapter(this , fourList);
		list4.setAdapter(adapters4, 3);
		list4.setXListViewListener(this);
		lists.add(list4);
		loadViews.add(loadView4);
		adapters.add(adapters4);
		pager.add(pager4);
		
		myorder_viewpager.setAdapter(new ListPagerAdapter(pager));
		myorder_viewpager.setOnPageChangeListener(this);
	}
	private void loadListFromLoadView(final int position) {
		lists.get(position).setPullLoadEnable(false);
		lists.get(position).setPullRefreshEnable(false);
		loadViews.get(position).startLoad();
        baseHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (testNum == 1) {
					if(position == 0){
						firstList.addAll(MyorderInfo.getTest());
					}
					else if(position == 1){
						secondList.addAll(MyorderInfo.getTest());
					}
					else if(position == 2){
						thirdList.addAll(MyorderInfo.getTest());
					}else
					{
						fourList.addAll(MyorderReceiveInfo.getTest());
					}
					
					
					
					
					
					if(position ==3)
					{
						adapters4.notifyDataSetChanged();
					}
					else
				    {
						adapters.get(position).notifyDataSetChanged();
				    }
				    
					
					loadViews.get(position).loadDone();

					lists.get(position).setPullLoadEnable(true);
					lists.get(position).setPullRefreshEnable(true);
				} else {
					loadViews.get(position).loadError(position);
					testNum++;
				}

			}
		}, 1000);
	}

	private void loadList(final int position , final boolean isLoadMore) {
		if (isLoadMore) {
			lists.get(position).setPullRefreshEnable(false);
		} else {
			lists.get(position).setPullLoadEnable(false);
		}

		baseHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if(position == 0){
					firstList.addAll(MyorderInfo.getTest());
				}
				else if(position == 1){
					secondList.addAll(MyorderInfo.getTest());
				}else if(position == 2){
					thirdList.addAll(MyorderInfo.getTest());
				}else
				{
					fourList.addAll(MyorderReceiveInfo.getTest());
				}
				
				if(position ==3)
				{
					adapters4.notifyDataSetChanged();
				}
				else
			    {
					adapters.get(position).notifyDataSetChanged();
			    }

				lists.get(position).stopLoadMore();
				lists.get(position).stopRefresh();
				if (isLoadMore) {
					lists.get(position).setPullRefreshEnable(true);
				} else {
					lists.get(position).setPullLoadEnable(true);
				}
			}
		}, 1000);
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		
		case R.id.back1:
			AppManager.getAppManager().finishActivity();
			break;
		default:
			break;
		}
	}

	@Override
	public void onRefresh(int type) {                                               //为了区分每一个选项下的List
		// TODO Auto-generated method stub
		pages[type] = 1;
		if(type == 0){
			firstList.clear();
		}else if(type == 1){
			secondList.clear();
		}else if(type == 2){
			thirdList.clear();
		}else
		{
			fourList.clear();
			
		}
		if(type ==3)
		{
			adapters4.notifyDataSetChanged();
		}
		else
	    {
			adapters.get(type).notifyDataSetChanged();
	    }
	    
		loadList(type , false);
		lists.get(type).setRefreshTime(StringUtil.getNowTime());
	}

	@Override
	public void onLoadMore(int type) {
		// TODO Auto-generated method stub
		pages[type] ++;
        loadList(type , true);
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageSelected(int arg0) {
		// TODO Auto-generated method stub
		pagerSwitch.setSelect(arg0);                      //
	}

	@Override
	public void reload(int type) {                            //ErrorClickListener中实现的方法
		// TODO Auto-generated method stub
		loadListFromLoadView(type);
	}

	@Override
	public void pagerChanged(int position) {                  //PagerSwitchListener中实现的方法
		// TODO Auto-generated method stub
		myorder_viewpager.setCurrentItem(position, true);
	}

	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void setOnClickListener() {
		// TODO Auto-generated method stub
		back.setOnClickListener(this);
	}

	@Override
	protected void refresh(Object... param) {
		// TODO Auto-generated method stub
		
	}

}

 


R.layout.common_list布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <com.driving.client.widget.xlistView.XListView
        android:id="@+id/xlistView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="#00000000"
        android:clickable="false"
        android:listSelector="@android:color/transparent" >
    </com.driving.client.widget.xlistView.XListView>
	    
	    <com.driving.client.widget.LoadView 
       		android:id="@+id/loadView"
       		android:layout_height="fill_parent"
       		android:layout_width="fill_parent"
       ></com.driving.client.widget.LoadView>

</RelativeLayout>



最后我把XListView实现的类通过文件传上去。以及其中的一些类。。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值