在GridView中向Android ImageView添加额外信息,以便识别它(Add extra info to Android ImageView in GridView so it can be identified)
我有一个GridView,其中的项目是ImageViews(在LinearLayout内)。 创建项的适配器获取参数位置,该位置指定当前正在创建的项列表中的哪个项。 如何将这些信息传递给ImageView,这样当它点击它时它会知道它是哪个图像?
创建项目的适配器如下所示。
public View getView(int position, View view, ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView = inflater.inflate(R.layout.new_ticket_image_view, null, true); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); imageView.setImageBitmap(bitmaps.get(position)); imageView.setOnClickListener((View.OnClickListener) this.context); return rowView; }I have a GridView where the items are ImageViews (inside a LinearLayout). The adapter that creates the item gets a parameter position, which specifies which item in the list of items that is now being created. How can I pass that information on to the ImageView so when it get's click it will know which image it is?
The adapter creating the items look like this.
public View getView(int position, View view, ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView = inflater.inflate(R.layout.new_ticket_image_view, null, true); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); imageView.setImageBitmap(bitmaps.get(position)); imageView.setOnClickListener((View.OnClickListener) this.context); return rowView; }最满意答案
使用方法setTag of view传递信息,使用getTag获取Listener中的信息。
Use method setTag of view to pass information and getTag to get information in Listener.
更多推荐
发布评论