QQ863017854 2016-03-04 03:24 采纳率: 100%
浏览 5484
已采纳

Android 如何在适配器中启动intent跳转activity

如题 如何在适配器中启动intent跳转activity

  • 写回答

2条回答

  • Exploring1024 2016-03-04 03:28
    关注

    你在适配器中传入context就可以了。

     public class ProductListAdapter extends BaseAdapter {
        private Context context;
        private List<String> listData;
        private ViewHolderProduct viewHolderProduct;
        public ProductListAdapter(Context context,List<String> listData){
            this.context = context;
            this.listData = listData;
        }
    
        @Override
        public int getCount() {
            return listData == null ? 0 : listData.size();
        }
    
        @Override
        public Object getItem(int position) {
            return listData == null ? null : listData.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null || convertView.getTag() == null){
                viewHolderProduct = new ViewHolderProduct();
                convertView = LayoutInflater.from(context).inflate(R.layout.product_item_layout,null);
                viewHolderProduct.iv_pro_pic = (ImageView) convertView.findViewById(R.id.iv_imageView);
                viewHolderProduct.tv_pro_date = (TextView) convertView.findViewById(R.id.tv_pro_date);
                viewHolderProduct.tv_pro_desc = (TextView) convertView.findViewById(R.id.tv_pro_desc);
                viewHolderProduct.tv_pro_from = (TextView) convertView.findViewById(R.id.tv_pro_from);
                viewHolderProduct.tv_pro_name = (TextView) convertView.findViewById(R.id.tv_pro_name);
                viewHolderProduct.tv_pro_number = (TextView) convertView.findViewById(R.id.tv_pro_number);
                viewHolderProduct.tv_pro_price = (TextView) convertView.findViewById(R.id.tv_pro_price);
                convertView.setTag(viewHolderProduct);
            }else{
                viewHolderProduct = (ViewHolderProduct) convertView.getTag();
            }
            viewHolderProduct.tv_pro_price.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LoginActivity.class);
                    context.startActivity(intent);
                }
            });
            return convertView;
        }
    
        class ViewHolderProduct{
            TextView tv_pro_number,tv_pro_name,tv_pro_desc,tv_pro_from,tv_pro_date,tv_pro_price;
            ImageView iv_pro_pic;
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配