简体   繁体   中英

How to use Edittext In GroupView of ExpandableListView, edittext cannot get focused

I have a ExpandableListView and each groupView has a EditText . If I set the edittext android:focusable=true then the groupView item cannot get focused, which means the group can't be expanded. If I set the ediitext android:focusable=false , then the edittext cannot get focused while de groupView can be expanded. I have tried to add code sheetListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); But it seems no use for me.

Here is the GroupView layout file: 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>

Here is my ExpandableListViewAdapter getGroupView code

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;
}

try below line in your root layout :-

before_descendent

in your xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM