子视图未显示可扩展列表视图

时间:2015-04-09 10:19:19

标签: android expandablelistview expandablelistadapter

问题:我已经和我分配给ExpandableListView的{​​{1}}了。我已经实施了BaseExpandableListAdapter方法来为每个孩子设置并返回getChildView()但是它没有显示子布局,它只显示父布局:

可扩展列表适配器:

View

public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_child_item, null); } //In child layout we are getting values from model class i.e. Category Model and setting it to text view TextView txtViewBusinessName = (TextView) convertView.findViewById(R.id.textViewBusinessName); txtViewBusinessName.setText(categoryModel.getBusinessName().trim()); Log.i(TAG,"(categoryModel.getBusinessName().trim()"+(categoryModel.getBusinessName().trim())); TextView txtViewPhoneNo = (TextView) convertView.findViewById(R.id.textViewMobileNo); txtViewPhoneNo.setText(categoryModel.getPhoneNumber().trim()); TextView txtViewLandmark= (TextView) convertView.findViewById(R.id.textViewLandmark); txtViewLandmark.setText(categoryModel.getLandMark().trim()); return convertView; } 课内,我写了以下代码:

MainActivity

我也对布局进行了更改。它还没有向我显示儿童数据。 只有父视图在布局中显示。请告诉我任何解决方案,为什么它没有显示&还有如何在运行时在子视图中添加数据。

2 个答案:

答案 0 :(得分:3)

组布局的可聚焦属性和组布局中的所有可单击视图都必须为false。如果不是,请尝试将它们设置为false。喜欢:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="false">
</RelativeLayout>

答案 1 :(得分:0)

对于那些在不久的将来遇到这个问题的人。我喜欢你,关注如何使用此ExpandableListView的互联网上的每个教程/示例,但遇到了子项目不显示的问题。

构建的API是API 22,我所做的解决方案是我明确地调用了ExpandableListView类的expandGroup()方法。

下面的内容

mExpandableTriggers.setAdapter(adapter);
mExpandableTriggers.expandGroup(0);
相关问题