【问题标题】:Android how to access views from my custom list if I use a CustomAdapter?如果我使用 CustomAdapter,Android 如何从我的自定义列表中访问视图?
【发布时间】:2012-02-21 07:52:40
【问题描述】:

在我的应用程序中,我有 ListView,它由我的 CustomAdapter(即 ArrayAdapter)设置。 CustomAdapter 在其中实现了 ViewHolder,它引用了我的 CustomList 中的所有视图。 现在我的问题是如何访问我的 CustomList 中的视图(如下面代码中的 EditText),因为类层次结构就像

public class BaseActivityClass{
    ...
    class CustomAdapter{
        ...
        public class ViewHolder{
            EditText et;
            ...
            }
        }
    }

来自我的活动 BaseActivityClass?

【问题讨论】:

    标签: android android-listview android-arrayadapter


    【解决方案1】:

    您可以在您的getView() 方法中为您的View 提供一个唯一的ID (View.setId()) 或标签(View.setTag()),然后使用findViewById()findViewByTag() 来使用它们

    【讨论】:

      【解决方案2】:

      在您的自定义适配器中

      public View getView(int position,View convertView,ViewGroup parent){
      LayoutInflater inflater=getLayoutInflater();
      View row=inflater.inflate("R.layout.yourcustomlistviewlayout ", parent, false);
      EditText et=(EditText)row.findViewById(R.id.youredittext);
      }
      

      这样您就可以控制您的自定义适配器视图

      【讨论】:

      • 如果edittext不是Listview的一部分而是Activity的一部分怎么办?
      猜你喜欢
      • 2011-04-02
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多