用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

Listview多条目加载

2016-12-16 作者: cwm1996举报

[android]代码库

/**
*一个XML实现Listview多条目加载
*/
package com.example.listview;

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

import com.example.bean.Data;
import com.example.bean.Iarge_image_list;
import com.example.bean.Image_list;
import com.example.bean.Middle_image;
import com.lidroid.xutils.BitmapUtils;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Myadapter extends BaseAdapter {

	private Context context;
	private List<Data> list;

	public Myadapter(Context context, List<Data> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder1 v1=null;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.item, null);
			v1=new ViewHolder1();
            v1.line1=(LinearLayout) convertView.findViewById(R.id.line1);
            v1.title1=(TextView) convertView.findViewById(R.id.title1);
            v1.imageView1=(ImageView) convertView.findViewById(R.id.line1_image1);
            v1.imageView2=(ImageView) convertView.findViewById(R.id.line1_image2);
            v1.imageView3=(ImageView) convertView.findViewById(R.id.line1_image3);
            v1.line2=(LinearLayout) convertView.findViewById(R.id.line2);
            v1.title2=(TextView) convertView.findViewById(R.id.title2);
            v1.line2_image=(ImageView) convertView.findViewById(R.id.line2_image);
            v1.line3=(LinearLayout) convertView.findViewById(R.id.line3);
            v1.title3=(TextView) convertView.findViewById(R.id.title3);
            v1.line3_image=(ImageView) convertView.findViewById(R.id.line3_image);
            v1.line4=(LinearLayout) convertView.findViewById(R.id.line4);
            v1.title4=(TextView) convertView.findViewById(R.id.title4);
            convertView.setTag(v1);
		}else{
			v1=(ViewHolder1) convertView.getTag();
		}
		List<Image_list> Image_list=new ArrayList<Image_list>();
		List<Iarge_image_list> Iarge_image_list=new ArrayList<Iarge_image_list>();
		List<String> Middle_image=new ArrayList<String>();
		Image_list.addAll(list.get(position).image_list);
		Iarge_image_list.addAll(list.get(position).large_image_list);
		Middle_image.add(list.get(position).middle_image.url);
		String title=list.get(position).title;
		if(Iarge_image_list.size()>0){
			v1.line3.setVisibility(View.VISIBLE);
			v1.line1.setVisibility(View.GONE);
			v1.line2.setVisibility(View.GONE);
			v1.line4.setVisibility(View.GONE);
			new BitmapUtils(context).display(v1.line3_image,Iarge_image_list.get(0).url);
			v1.title3.setText(title);
		}else
		if(Image_list.size()>0){
			v1.line1.setVisibility(View.VISIBLE);
			v1.line3.setVisibility(View.GONE);
			v1.line2.setVisibility(View.GONE);
			v1.line4.setVisibility(View.GONE);
			new BitmapUtils(context).display(v1.imageView1,Image_list.get(0).url);
			new BitmapUtils(context).display(v1.imageView2,Image_list.get(1).url);
			new BitmapUtils(context).display(v1.imageView3,Image_list.get(2).url);
			v1.title1.setText(title);
		}else
		if(Middle_image.size()>0){
			v1.line2.setVisibility(View.VISIBLE);
			v1.line3.setVisibility(View.GONE);
			v1.line1.setVisibility(View.GONE);
			v1.line4.setVisibility(View.GONE);
			new BitmapUtils(context).display(v1.line2_image,Middle_image.get(0));
			v1.title2.setText(title);
		}else{
			v1.line4.setVisibility(View.VISIBLE);
			v1.line2.setVisibility(View.GONE);
			v1.line3.setVisibility(View.GONE);
			v1.line1.setVisibility(View.GONE);
			v1.title4.setText(title);
		}
		
		return convertView;
	}
	class ViewHolder1{
		LinearLayout line1,line2,line3,line4;
		TextView title1,title2,title3,title4;
		ImageView imageView1,imageView2,imageView3,line2_image,line3_image;
	}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...