如何访问从一个活动列表适配器创建UI元素? [英] How to access UI elements created by a List Adapter from an Activity?

查看:128
本文介绍了如何访问从一个活动列表适配器创建UI元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我现在的code,我有一个DetailActivity,它只是调用ListAdapter类来填充一个ListView。

In my code now, I have a DetailActivity, which simply calls a ListAdapter class to populate a ListView.

在ListAdapter类,我夸大了一些自定义视图,其中一些含有按钮。

Within the ListAdapter class, I am inflating some custom views, some of which contain Buttons.

返回从我DetailActivity内,我希望能够访问这些按钮启用/禁用它们根据特定用户操作。有没有办法做到这一点?

Back from within my DetailActivity, I would like to be able to access these buttons to enable/disable them depending on certain user actions. Is there a way to do this?

我想更大的问题是:从活动中,我怎么能抓住任何一个元素的引用(按钮,imageviews,textviews等),这些从适配器创建

I guess the larger question is: from an Activity, how can I grab a reference to any element (buttons, imageviews, textviews,etc) that are created from an Adapter?

感谢您!

推荐答案

我假设你有一个列表<对象> ,它通过ListAdapter的构造函数发送。
只需添加一个布尔isEnable 对象,然后在你的 getView()方法,添加此行:

I assume you have a List<Object> that is sent through the constructor of ListAdapter. Just add a boolean isEnable to the Object, and then in your getView() method, add this line:

button.setEnabled(getItem(position).isEnable);

在你的 DetailActivity ,您可以更改 isEnable 如你所愿。要记住, adapter.notifyDataSetChanged()来得到它的工作。

In your DetailActivity, you can changeisEnable as you wish. And remember to adapter.notifyDataSetChanged() to get it worked.

这篇关于如何访问从一个活动列表适配器创建UI元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆