每一排的ListView与巴顿preSS状态问题 [英] Issues with Button press states in each ListView row

查看:136
本文介绍了每一排的ListView与巴顿preSS状态问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用中的ListView行按钮presses问题。每个按钮的背景属性指的是一个XML文件选择;为了选择按钮presses不同的图像。
我能够从OnClickListener preSS事件,但状态选择休息,不与注册presses安卓STATE_ pressed =真正的的android:state_focused =FALSE

I'm having problems with button presses in ListView rows. The background attribute for each Button refers to a XML selector file; in order to select a different image on button presses. I'm able to get press events from OnClickListener, but the state selector breaks and does not register presses with android:state_pressed="true" and android:state_focused="false".

如果我删除的android:descendantFocusability =blocksDescendants从父/根布局XML的按钮;那么preSS状态将工作,但将火无论身在何处,你在ListView中的行,这是烦人碰。

If I remove android:descendantFocusability="blocksDescendants" from the parent/root Layout XML for the button; then the press state will work, but will fire no matter where you touch on the ListView row, which is annoying.

我的问题:行从内按钮分开无法管理preSS /默认状态。他们互相干扰。

My problem: cannot manage the press/default states of rows separate from the buttons inside. They interfere with each other.

code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/mainListLayout"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:descendantFocusability="blocksDescendants">
..........

行项目按钮进一步下跌:

Row item button further down:

<Button
        android:id="@+id/deleteButton"
        android:background="@drawable/del_button_selector"
        .....
        .....
        />
..........

和提拉/ del_button_selector:

And the drawable/del_button_selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/deleteico" android:state_focused="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/deletepressed" android:state_focused="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/deleteico" android:state_focused="false" android:state_pressed="true" />

更改在最后选择线有不工作的绘制背景。它会显示在pressed的形象,但你来自哪里按钮点击行,走也没关系。

Changing the drawable background in the last selector line there does not work. It will show the pressed image but it does not matter where you click on the row, away from the button.

我可以改变按钮点击事件的背景,但我需要切换到默认按钮后释放,这是很难捕捉背景(?)。如果我能捕捉听众preSS /释放事件那么这将是伟大的按钮而已。

I can change the background on button click events but I need to switch back to default background upon button release, which is hard to capture(?). If I can capture press/release events in listeners then that would be great for buttons only.

任何帮助AP preciated!谢谢!

Any help appreciated! Thanks!

推荐答案

容易的解决方案是设置的android:点击=真正的父视图。

The easy solution is to set android:clickable="true" to the parent view.

这样它会拦截触摸事件和孩子的意见将不会被高亮显示。

This way it will intercept the touch event and the child views will not be highlighted.

在您的具体情况:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainListLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" 
      android:clickable="true">

这篇关于每一排的ListView与巴顿preSS状态问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆