在GridView中向Android ImageView添加额外信息,以便识别它(Add extra info to Android ImageView in GridView so it can b

编程入门 行业动态 更新时间:2024-10-25 00:32:21
在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.

更多推荐

本文发布于:2023-04-29 10:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336402.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中向   信息   ImageView   Android   GridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!