ListView的item点击事件 虽然 不懂 Selector 是什么东东 ,但我知道android 的事件 分发 以及拦截。覆写 某些方法拦截事件我也不知道如何拦截 。 忘了,android 如此博大精深 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Y你还是把demo贴出来吧,我和老八都试过没出现你说的情况。 可以尝试加入这三个属性android:clickable="false" android:focusable="false" android:focusableInTouchMode="false"实在不行可以在OnItemClickListener里面进行强制修改 selector_shape_btn_blue.xml<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <corners android:radius="3dp" /> <solid android:color="@color/red" /> </shape> </item> <item> <shape> <corners android:radius="3dp" /> <solid android:color="@color/blue" /> </shape> </item></selector>selector_shape_btn_gray.xml<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"> <shape> <corners android:radius="2dip"/> <solid android:color="@color/gray_btn_fouce" /> </shape> </item> <item> <shape> <corners android:radius="2dip"/> <solid android:color="@color/gray_btn" /> </shape> </item></selector> main.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ListView android:id="@+id/lvmain" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:descendantFocusability="blocksDescendants" android:listSelector="@drawable/selector_shape_btn_gray" /></RelativeLayout>item.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="100dip" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <TextView android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/selector_shape_btn_blue" android:text="aadfasfadsf" /></LinearLayout>点击item的时候item变色,button变色(我希望button不变色)点击button的时候item没有变色,不头痛变色 加属性没效果在OnItemClickListener里强制修改是怎么修改?把button的颜色变回去? 方法1:别用TextView,改为Button,并加上focusable<Buttonandroid:id="@+id/btn" android:focusable="false"方法2:在Adapter的getView里给btn绑定ontouchview.findViewById(R.id.btn).setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); if (MotionEvent.ACTION_DOWN == action) v.setSelected(true); else if (MotionEvent.ACTION_MOVE != action) v.setSelected(false); return false; } });修改selector_shape_btn_blue.xml <item android:state_pressed="true"> 为 <item android:state_selected="true">如果还有更简单的方法请回复我,谢谢! 我之前写的就是Button 我是为了试试TextView能不能用所以才改的, <item android:state_pressed="true"> 为 <item android:state_selected="true">修改后Button没有效果。touch之前我就用过,不过这个不太方便。所以我想看看能不能改好。直接使用Selector。 可以使用了Shape改就不方便,还得单独写成xml. IDA+GDB调试安卓c代码[原创] 解释一下这个 送分! 用opengl做一个页面翻转的效果,求达人相助 请问android创建的AVD模拟器 默认的长和宽是多大? android编码的磨叽继承自哪里? 求教,能不能在监听器类中实现弹出对话框呀?(在线等) android中如何使用iptables进行port mapping ? 按钮的子菜单 三星 4.3系统上的Gsensor开发 clipse android开发,使用已有的keystore再签名,不能更改版本号 android 定时更新数据 如何设置AutoCompleteTextView 自动选择内容的字体大小
android:focusable="false"
android:focusableInTouchMode="false"
实在不行可以在OnItemClickListener里面进行强制修改
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<corners android:radius="3dp" />
<solid android:color="@color/red" />
</shape>
</item>
<item>
<shape>
<corners android:radius="3dp" />
<solid android:color="@color/blue" />
</shape>
</item>
</selector>
selector_shape_btn_gray.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<corners android:radius="2dip"/>
<solid android:color="@color/gray_btn_fouce" />
</shape>
</item>
<item>
<shape>
<corners android:radius="2dip"/>
<solid android:color="@color/gray_btn" />
</shape>
</item>
</selector>
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/lvmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:descendantFocusability="blocksDescendants"
android:listSelector="@drawable/selector_shape_btn_gray" />
</RelativeLayout>
item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="100dip"
android:layout_height="match_parent"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <TextView
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_shape_btn_blue"
android:text="aadfasfadsf" /></LinearLayout>
点击item的时候item变色,button变色(我希望button不变色)
点击button的时候item没有变色,不头痛变色
在OnItemClickListener里强制修改是怎么修改?把button的颜色变回去?
<Button
android:id="@+id/btn"
android:focusable="false"
方法2:在Adapter的getView里给btn绑定ontouchview.findViewById(R.id.btn).setOnTouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (MotionEvent.ACTION_DOWN == action)
v.setSelected(true);
else if (MotionEvent.ACTION_MOVE != action)
v.setSelected(false);
return false;
}
});
修改selector_shape_btn_blue.xml
<item android:state_pressed="true"> 为 <item android:state_selected="true">如果还有更简单的方法请回复我,谢谢!
<item android:state_pressed="true"> 为 <item android:state_selected="true">修改后Button没有效果。
touch之前我就用过,不过这个不太方便。
所以我想看看能不能改好。直接使用Selector。