如题 如何在适配器中启动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; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 7无用 1
悬赏问题
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
- ¥20 matlab yalmip kkt 双层优化问题
- ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
- ¥88 实在没有想法,需要个思路
- ¥15 MATLAB报错输入参数太多
- ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件