Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpandableListView with an EditText

I have an ExpandableListView where each parentView has an EditText (and a textview) in it. When i added the EditText to the Layout it would no longer let me click or expand the ExpandableListView, all focus just goes to the EditText. Is there a way to make both the EditText and the ExpandableListView itself be clickable? I want to be able to click the expandableListView to expand the list, and the EditText to be able to enter text.

Thanks

EDIT: added code of my group view

    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater inflater =  (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.group_row, null);
        }

        TextView playerName = (TextView) convertView.findViewById(R.id.playerName);
        playerName.setText(groupElements[groupPosition]);
        final EditText holeScore = (EditText) convertView.findViewById(R.id.score);
        holeScore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(scoreCard.this, "On CLick", Toast.LENGTH_SHORT).show();
                holeScore.setFocusable(true);
            }
        });
        return convertView;
    } 
like image 865
user1154920 Avatar asked Apr 10 '12 02:04

user1154920


1 Answers

The problem is because of EditText's default focusablitiy. Since they are capable of getting focused by default this will make your parent view to be unfocused. So what you have to do is remove the focus capability of your EditText by using,

andorid:focusable="false".

And similarly if you are having any button in your parent, setting focusable false to it also will help. This is the only way you can make your parent view to get clicked.

like image 153
Andro Selva Avatar answered Sep 29 '22 00:09

Andro Selva