如何使用Edittext在ExpandableListView的GroupView中,edittext无法聚焦

时间:2015-12-11 04:57:44

标签: android android-edittext expandablelistview

我有一个ExpandableListView,每个groupView都有一个EditText。 如果我设置了edittext android:focusable=true,则groupView项无法获得焦点,这意味着无法展开该组。如果我设置了ediitext android:focusable=false,则在展开de groupView时,edittext无法聚焦。我试图添加代码 sheetListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 但对我来说似乎毫无用处。

以下是GroupView布局文件:R.layout.item_receiving_scan_box

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    ...
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:gravity="center_vertical"
        android:inputType="number"
        android:ems="7"
        android:id="@+id/edittext_receiving_scan_box_count_count"
        android:text="20"
        android:textSize="12dp"
        android:focusable="false"
        android:clickable="true"
        android:layout_alignTop="@+id/text_receiving_scan_box_scan_count"
        android:layout_toRightOf="@+id/text_receiving_scan_box_scan_count"
        android:layout_toEndOf="@+id/text_receiving_scan_box_scan_count" />
</RelativeLayout>

这是我的ExpandableListViewAdapter getGroupView代码

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    RelativeLayout layout= (RelativeLayout) mLayoutInflater.inflate(R.layout.item_receiving_scan_box, null);
    TextView matCode = (TextView) layout.findViewById(R.id.text_receiving_scan_box_mat_code);
    TextView boxCount = (TextView) layout.findViewById(R.id.text_receiving_scan_box_count);
    matCode.setText(matCode.getText()+mReceivingBoxes.get(groupPosition).get("matCode"));
    boxCount.setText(boxCount.getText()+mReceivingBoxes.get(groupPosition).get("boxCount"));
    return layout;
}

1 个答案:

答案 0 :(得分:0)

在根布局中尝试以下行: -

before_descendent
你的xml中的