码迷,mamicode.com
首页 > 移动开发 > 详细

android listview左右滑动分页(viewpager嵌套listview进行分页),焦点图带圆焦点

时间:2014-05-04 18:43:02      阅读:585      评论:0      收藏:0      [点我收藏+]

标签:android   des   blog   class   code   java   

1、先上图后说话

bubuko.com,布布扣

2、代码

package com.example.exmp;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListViewPagerAdapter extends PagerAdapter{
	Context context;
	
	List<View> mListViewPager = new ArrayList<View>(); // ViewPager对象的内容
	List<String> list = new ArrayList<String>();
	List<List<String>> lcontant = null;
	int pageNum = 1;
	CustomIndicator mCustomIndicator;
	int pageRows=5;

	/**
	 * 
	 * @param context 活动窗体
	 * @param kf 数据
	 * @param customIndicator 圆点控件
	 * @param rows 每页显示多少条数据
	 */ 
	public ListViewPagerAdapter(final Context context, List<String> kf,CustomIndicator customIndicator,int rows) {
		this.mCustomIndicator=customIndicator;
		this.pageRows=rows;
		int count = 0;  //循环次数
		int pos = 0;		//当前位置
		
		this.context = context;
		this.list = kf;
		//计算页数
		pageNum = (int) Math.ceil(list.size() / pageRows);
		int a=list.size() % pageRows;
		if (a>0) {
			pageNum=pageNum+1;
		}
		
		
		mCustomIndicator.setCount(pageNum);
		Log.d("hx2", String.valueOf(pageNum));
		if (Math.ceil(kf.size() / pageRows) == 0) {
			pageNum = 1;
		}
		lcontant = new ArrayList<List<String>>();
		for (int i = 0; i < pageNum; i++) {
			Log.d("hx2", String.valueOf(i));
			List<String> item = new ArrayList<String>();
			for(int k = pos;k<kf.size();k++){
				count++;
				pos = k;
				item.add(kf.get(k));
				//每个List六条记录,存满N个跳出
				if(count == pageRows){
					count = 0;
					pos = pos+1;
					break;
				}
			}
			lcontant.add(item);
		}

		for (int j = 0; j < pageNum; j++) {
			View viewPager = LayoutInflater.from(context).inflate(
					R.layout.list, null);
			ListView mList = (ListView) viewPager.findViewById(R.id.wifi_list);
			final Myadapter myadapter=new Myadapter(context, lcontant.get(j));
			mList.setAdapter(myadapter);
			mListViewPager.add(viewPager);
			mList.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					
					final TextView content=(TextView) view.findViewById(R.id.ssid);
					Toast.makeText(context, "点击到"+content.getText(), Toast.LENGTH_LONG).show();

					
				}
			});
		}

	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public int getCount() {
		return mListViewPager.size();
	}

	@Override
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(mListViewPager.get(position));
		return mListViewPager.get(position);

	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
	}

	@Override
	public void destroyItem(View container, int position, Object arg2) {
		ViewPager pViewPager = ((ViewPager) container);
		pViewPager.removeView(mListViewPager.get(position));
	}

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

}
3、先敬告学者:如在此项目上运行不了的或者关于本项目的问题可以直接找到本人QQ:508181017,这是在别人的基础上修改自己想要的东西!
4、下载地址:待会会上传

android listview左右滑动分页(viewpager嵌套listview进行分页),焦点图带圆焦点,布布扣,bubuko.com

android listview左右滑动分页(viewpager嵌套listview进行分页),焦点图带圆焦点

标签:android   des   blog   class   code   java   

原文地址:http://blog.csdn.net/icqapp/article/details/24978057

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!