我已经在本教程http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/之后创建了一个ExpandableListView
,它运行正常。父组中有2 TextView
。但是当我在父组中添加EditText
时,它会在listview
中显示,但在点击父级后它不会扩展。我认为这是由于focus
上的EditText
。
请帮助找到父项目focus
的方法,以便点击它展开并显示子项目。另一方面,当我尝试在EditText
中写一些内容时,应该关注它而不扩展ListView
。
这是我的代码:
package com.sifb.icms.sit.application.adapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.sifb.icms.sit.R;
import com.sifb.icms.sit.object.Object_CateringMenu;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.TextView;
public class ExpandableListAdapter_CateringMenu extends BaseExpandableListAdapter {
private Context _context;
private List<Object_CateringMenu> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, String> _listDataChild;
public ExpandableListAdapter_CateringMenu(Context context, ArrayList<Object_CateringMenu> listDataHeader,
HashMap<String, String> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition).getCategoryChoice());
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_cateringmenu_description, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.tvDescription);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Object_CateringMenu objGroup = (Object_CateringMenu) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_cateringmenu, null);
}
TextView lblListHeaderCat = (TextView) convertView
.findViewById(R.id.tvCategoryChoice);
lblListHeaderCat.setTypeface(null, Typeface.BOLD);
lblListHeaderCat.setText(objGroup.getCategoryChoice());
TextView lblListHeaderRatio = (TextView) convertView
.findViewById(R.id.tvRatio);
lblListHeaderRatio.setTypeface(null, Typeface.BOLD);
lblListHeaderRatio.setText(objGroup.getRatio());
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/svParent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvTitle"
style="@style/tvTitleText"
android:text="@string/cateringmenu_title" />
<include
android:id="@+id/include_cateringmenu_header"
layout="@layout/list_cateringmenu_header" />
<ExpandableListView
android:id="@+id/elvCateringMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="@android:color/transparent"
android:descendantFocusability="beforeDescendants"
android:layout_marginTop="10dp" />
</LinearLayout>
父ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="@+id/tvCategoryChoice"
style="@style/tvCateringMenu"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_weight="0.5" />
<TextView
android:id="@+id/tvRatio"
style="@style/tvCateringMenu"
android:layout_weight="0.2" />
<EditText
android:id="@+id/etMealUplift"
style="@style/etCateringMenuMealUplift"
android:layout_weight="0.3" />
</LinearLayout>