找传奇、传世资源到传世资源站!

ListView和适配器的使用详细介绍_

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

package com.great.baseadapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyBaseAdapter extends BaseAdapter {

private Context context;
private ArrayList<MyData> list;
private MyData data;
private ViewHolder holder;

public MyBaseAdapter(Context context, ArrayList<MyData> list) {
super();
this.context = context;
this.list = list;
}
//返回条目数
@Override
public int getCount() {
return list.size();
}
//得到某一条目
@Override
public Object getItem(int position) {
return list.get(position);
}
//返回条目值
@Override
public long getItemId(int position) {
return position;
}
//进行适配
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv_01 = null,tv_02=null;
//产生View
if(convertView==null)
{
convertView = LayoutInflater.from(context).inflate(R.layout.actvity_item, null);
holder = new ViewHolder();
holder.tv_01 = (TextView) convertView.findViewById(R.id.tv_01);
holder.tv_02 = (TextView) convertView.findViewById(R.id.tv_02);

//tv_01.setText(list.get(position).getText1());
//tv_02.setText(list.get(position).getText2());
convertView.setTag(holder);

}
else
{
holder = (ViewHolder) convertView.getTag();
// tv_01 = (TextView) convertView.findViewById(R.id.tv_01);
// tv_02 = (TextView) convertView.findViewById(R.id.tv_02);
//
// tv_01.setText(list.get(position).getText1());
// tv_02.setText(list.get(position).getText2());
}

holder.tv_01.setText(list.get(position).getText1());
holder.tv_02.setText(list.get(position).getText2());

return convertView;
}

private class ViewHolder
{
private TextView tv_01;
private TextView tv_02;
}

}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复