【问题标题】:button in expandable listview android可扩展列表视图android中的按钮
【发布时间】:2012-04-10 11:27:33
【问题描述】:

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

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

有什么方法可以放一个可以点击的按钮,并且expandablelist不会失去展开的功能?

【问题讨论】:

    标签: android expandablelistview expandablelistadapter


    【解决方案1】:

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

    【讨论】:

    • (按钮)应该是(按钮)
    • 又一个 wtf 的 android 时刻
    • 非常感谢。你对这种行为有什么解释吗?从我的角度来看,它看起来与扩展功能无关......
    • 在我的情况下,我有一个 ScrollView 并且在 ListView 中具有相同的行为。当可见时,列表的 OnItemClickListener 不再起作用(可能是焦点问题,或双滚动问题......不是清除)
    【解决方案2】:

    您不仅可以在类中设置“focusable”属性,还可以在 xml 中设置,至少它对我有用。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多