简体   繁体   English

可扩展listview android中的按钮

[英]button in expandable listview android

i have a ExpandableListActivity with an custom Adapter. 我有一个自定义适配器的ExpandableListActivity。

if the custom row of the adapter contains a imageViewall is done, but if i change this view from imageView to imageButton, the expandable listview don't expand. 如果适配器的自定义行包含imageViewall已完成,但如果我将此视图从imageView更改为imageButton,则可扩展列表视图不会展开。

Is there any method to put a button that can be clicked and the expandablelist does not lose the functionality to expand? 是否有任何方法可以放置一个可以单击的按钮,并且expandablelist不会丢失扩展功能?

The button should be no-focuseable. 按钮应该是不可聚焦的。 In your listView.setOnItemClickListener (not in xml layout!!) : 在listView.setOnItemClickListener中(不在xml布局中!!):

Button button = (Button) view.findViewById(R.id.yourButton); 
//where button is the button on listView, and view is the view of your item on list

button.setFocusable(false);   /// THIS IS THE SOLUTION

button.setOnClickListener(new Button.OnClickListener() {
    public void onClick(View v) {
        //button functionalty   ...
    }
});

You can set the 'focusable' attribute not just in the class, but in the xml as well, at least it's working for me. 您不仅可以在类中设置'focusable'属性,还可以在xml中设置,至少它对我有用。

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"/>

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

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