对ListView的Item子控件监听并跳转页面
2024-09-04 20:08:26
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; }
}
最新文章
- 关系型数据库与NoSQL数据库
- SQLite学习笔记(十二)&;&;虚拟机指令
- 用VB实现SmartQQ机器人
- Unix调试工具dbx使用方法
- Java中“==”与equals方法的区别
- 使用Discuz关键词服务器实现PHP中文分词
- Android EditText边框颜色的selector 使用focus标记当前填写的框
- 如何让centos6.5在vm11里上网,连接网络?
- 【细说Java】方法重载的简单介绍
- SPA 单页面应用
- 转:JMeter进行Java 请求测试
- web&mdash;URL不同形式地址的问题
- Algorithm -->; 判读是否是子树
- java的集合:List、Set和Map
- JavaScript视频分享,学无止境。
- 简单的TSQL基础编程格式,存储过程,视图
- 查询rman 备份信息集
- opencv入门指南(转载)
- python的sciter库Pysciter安装教程(win32 + win64)
- Python练习-基于socket的FTPServer