Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditTexts inside ExpandableListView

Hi I'm trying to make an activity that displays an ExpandableListView as shown in the figure.

When you click on the group it expands and shows a LinearLayout with a textview and an editext.

Right know the problem I have is that when a click on the EditText it doesn't get focus and I have to tap twice on it in order to make it get focus and display the keyboard, and then when I enter text I see nothing initially while I'm typing and then when I hide the Keyboard the EditText is updated with the text I typed

I've tried adding android:descendantFocusability="afterDescendants" to the expandableListVie layout, but the behaviour is the same.

Any Idea?? or any other way I could implement this layout??

Expandable ListView with EditText

like image 819
Julian Suarez Avatar asked Feb 23 '23 10:02

Julian Suarez


2 Answers

add this to the manifest right after the android:name in your activity

 android:windowSoftInputMode="adjustPan"
like image 80
Pareek Ravi Avatar answered Mar 07 '23 19:03

Pareek Ravi


I am not sure how to fix the focusing problem, but I know why you have to collapse and expand the group to see the text in the editText. The listview doesn't refresh unless you scroll or you do something like expanding and collapsing the listview. So the best way I can think of to fix this problem is to create a list of strings that will be the values of the editTexts in the listview. Then create a onKeyClick() listener for each of the editTexts and do this:

editText1.setOnKeyListener(new EditText.OnKeyListener()
{
    public boolean onKey(View editText, int keyCode, KeyEvent keyEvent)
    {
        // Get the position of the item somehow
        int position = 4;
        // Get value from List<String> for editTexts
        String textValue = listOfValues.get(position);
        textValue = ((EditText)editText).getValue();
        adapter.notifyDataSetChanged();
        return false;
    }
});

What happens here is that you are getting the value of the editText once a key has been pressed, and are changing the value of the string in the list to the new value. Then you are telling the adapter that the value of one of the items has changed an it needs to refresh. Although this is not an efficient way to fix the problem, it is a backup solution in case you can't think of a better way.

like image 32
A. Abiri Avatar answered Mar 07 '23 18:03

A. Abiri