简体   繁体   English

带有 EditText 的 ExpandableListView

[英]ExpandableListView with an EditText

I have an ExpandableListView where each parentView has an EditText (and a textview) in it.我有一个 ExpandableListView,其中每个 parentView 都有一个 EditText(和一个 textview)。 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.当我将 EditText 添加到布局时,它不再让我单击或展开 ExpandableListView,所有焦点都转到 EditText。 Is there a way to make both the EditText and the ExpandableListView itself be clickable?有没有办法让 EditText 和 ExpandableListView 本身都可以点击? I want to be able to click the expandableListView to expand the list, and the EditText to be able to enter text.我希望能够单击 expandableListView 展开列表,单击 EditText 能够输入文本。

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

The problem is because of EditText's default focusablitiy.问题是因为 EditText 的默认 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,所以你要做的是通过使用删除你的 EditText 的焦点功能,

andorid:focusable="false".

And similarly if you are having any button in your parent, setting focusable false to it also will help.同样,如果您的父母有任何按钮,将 focusable false 设置为它也会有所帮助。 This is the only way you can make your parent view to get clicked.这是使父视图被点击的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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