zoukankan      html  css  js  c++  java
  • 对ListView的Item子控件监听并跳转页面

    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;
    
        }
    }
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    使用Nginx实现反向代理
    nginx配置
    jsonp跨域实现单点登录,跨域传递用户信息以及保存cookie注意事项
    jsonp形式的ajax请求:
    面试题
    PHP设计模式_工厂模式
    Redis限制在规定时间范围内登陆错误次数限制
    HTTP 状态码简介(对照)
    Django 进阶(分页器&中间件)
    Django 之 权限系统(组件)
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/5751261.html
Copyright © 2011-2022 走看看