Deepak
Deepak

Reputation: 491

Expandable list with edit text on grouplayput in android

I have created an expandable ListView, in which I have created a custom group layout.

On the group layout I have created an EditText on the right side. Whenever I put text on the EditText and click on the expandable list, the list does not expand/collapse.

When I do focusable false of EditText then list is expand/collapse.

How to solve this problem? Please suggest me.

Upvotes: 1

Views: 1712

Answers (2)

Deepak
Deepak

Reputation: 491

Today,I have resolved the above problem on expandable List and N-Level expandable list view. I have attached the code. Firstly,I have set focusable false of edit text on your activity/adapter,do not on xml of EditText.

EditText.setFocusable(false);

Secondly,I have used touch listener because here I set focusable true of edit text.So that I can easily type text on edit box.

EditText.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                EditText.setFocusableInTouchMode(true);
                return false;
            }
        });

After that, I have used KeyListener because here I am getting data and set value on hash map according to position/group position.so that whenever I am clicked on 2-level or N-level expandable list view data is not changed.That is very important on expandable list view.On done key press I am hiding keyboard.And set focusable false of edit text,so that I can expand/collapse freely.

EditText.setOnKeyListener(new OnKeyListener() {
            String editValue;
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                {
                    editValue=groupHolder.numberEdit.getText().toString().trim();
                    EditText.setFocusable(false);
                    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY,0);
                }
                setEditValueHashMap.put(groupPosition, editValue);
                return false;
            }
        });

Upvotes: 1

Arpit Garg
Arpit Garg

Reputation: 8546

Edit Text is itself a focus-sable component. If we place inside the list view, expandable list then the list click and collapse expand property will not work. Same problem arose when you use EditText, Button, ImageButton, etc,

So you need to use:

1.Use following property in Expandable List :

 android:descendantFocusability="blocksDescendants"

or 2. Use the following property in EditText

android:focusable="false"

Upvotes: 1

Related Questions