繁体   English   中英

可扩展listview android中的按钮

[英]button in expandable listview android

我有一个自定义适配器的ExpandableListActivity。

如果适配器的自定义行包含imageViewall已完成,但如果我将此视图从imageView更改为imageButton,则可扩展列表视图不会展开。

是否有任何方法可以放置一个可以单击的按钮,并且expandablelist不会丢失扩展功能?

按钮应该是不可聚焦的。 在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   ...
    }
});

您不仅可以在类中设置'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