public class MyAdapteforOwner extends BaseAdapter{
List<OwnerDevice>datas;
private Context context;
Activity activity;
//这里传入一个datas和context即可
public MyAdapteforOwner(List<OwnerDevice> datas, Context context, Activity activity) {
this.datas = datas;
this.context = context;
this.activity=activity;
} @Override
public int getCount() {
return datas.size();
}
@Override
public Object getItem(int position) {
return datas.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
if(convertView==null){
convertView=View.inflate(context,R.layout.owneritem_layout,null);
holder=new ViewHolder();
holder.textView1= (TextView) convertView.findViewById(R.id.bts_name);
holder.textView2= (TextView) convertView.findViewById(R.id.text1);
holder.textView3= (TextView) convertView.findViewById(R.id.text2);
holder.textViewdetail= (TextView) convertView.findViewById(R.id.text_detail);
holder.textViewmap= (TextView) convertView.findViewById(R.id.text_map);
convertView.setTag(holder);
}else{
holder= (ViewHolder) convertView.getTag();
}
OwnerDevice ownerDevice=datas.get(position);
String bts_name=ownerDevice.getBts_name(); holder.textView1.setText(bts_name);
holder.textView2.setText("地址: "+ownerDevice.getAddress());
holder.textView3.setText("状态:"+ownerDevice.getAl_accountIdRepair());
//实现子控件监听,在adapter里面写监听事件
holder.textViewmap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//点击查看地图实现方法
//t跳转页面需要有context调用startActivity
Intent intent=new Intent((Activity)context, Map_Activity.class);
((Activity)context).startActivity(intent);
}
}); holder.textViewdetail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { }
});
return convertView;
}
class ViewHolder{
TextView textView1 ,textView2,textView3;
TextView textViewmap,textViewdetail; }
}