【问题标题】:Why is .getChildCount() always zero for my ExpandableListView?为什么我的 ExpandableListView 的 .getChildCount() 始终为零?
【发布时间】:2018-03-01 15:43:35
【问题描述】:

我有一个ExpandableListView,声明为:

private ExpandableListView mELV_PredefinedFruit;

并使用 extends BaseExpandableListAdapter 的适配器。它以 2 组(均已展开)的不同孩子正确显示在屏幕上。 但是我总是得到零,我在结束时检查孩子的数量 Activity onCreate 使用以下内容:

int numberOfChildViews = mELV_PredefinedFruit.getChildCount();
Log.d(LOG_CLASS, String.format(Locale.US, "%s number of child views in ELV:  %d", METHOD, numberOfChildViews));

为什么总是零?

【问题讨论】:

    标签: java android expandablelistview expandablelistadapter


    【解决方案1】:

    你得到 0,因为你的视图还没有准备好。 试试这个:

    mELV_PredefinedFruit.post(new Runnable() {
        @Override
        public void run() {
            int numberOfChildViews = mELV_PredefinedFruit.getChildCount();
            Log.d(LOG_CLASS, String.format(Locale.US, "%s number of child views in ELV:  %d", METHOD, numberOfChildViews));
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 1970-01-01
      • 2016-05-02
      • 2012-01-16
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多