【发布时间】:2015-01-29 14:46:22
【问题描述】:
我想为此使用涟漪效应,我设置为android:clickable="true",但是当我这样做时,onClick 事件不起作用,但onLongClick 正在起作用。我该如何解决这个问题?
如果我不设置android:clickable,它就可以工作。
我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:longClickable="true"
android:background="@drawable/ripple">
代码:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.w("Item Clicked","Ok");
}
});
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
Log.w("Item Long Clicked","Ok");
}
});
【问题讨论】:
-
LogCat 有错误吗?
-
没有没有错误
-
@Override 注释在哪里?复制/粘贴错误还是您没有此注释?
-
好的,你确定你已经在 LogCat 过滤器中添加了“Item Clicked”吗?
-
你试过你的
LinearLayout设置android:focusable="true"和android:focusableInTouchMode="true"吗?
标签: android