正如标题中所说,我有一个滚动视图,它应该监听长点击,但没有捕捉到任何点击。当我按住滚动视图时,没有任何反应--没有日志,没有触觉反馈,也没有对话。
提前感谢!
JAVA:
...
ScrollView text_sv = (ScrollView) findViewById(R.id.text_sv);
text_sv.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
MMMLogs.i("click", "long-click recognized");
AlertDialog.Builder builder = new AlertDialog.Builder(_this);
builder
.setTitle(name)
.setMessage(DHMenuStorage.notification)
.setCancelable(false)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
});
...XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<ScrollView
android:id="@+id/text_sv"
android:layout_width="match_parent"
android:layout_height="75dp"
android:hapticFeedbackEnabled="true"
android:clickable="true"
android:longClickable="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/Gray"
android:focusable="false"
android:gravity="center"
android:padding="4dp"
android:text="-- Dining Hall Name --"
android:textColor="@color/Black"
android:textSize="28dp"
android:textStyle="bold" />
<TextView
android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/Gray"
android:focusable="false"
android:gravity="center"
android:padding="4dp"
android:text="-- Special note here --"
android:textColor="@color/Black"
android:textSize="14dp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
发布于 2012-06-22 11:39:19
好吧,我从来没有找出我的问题的确切来源,但我怀疑它与scrollview自己滚动所需的侦听器之间存在某种冲突。
我通过在线性布局上而不是在滚动视图上设置完全相同的侦听器来解决这个问题。很简单。希望它能帮上忙!
发布于 2014-04-14 17:34:09
看看ScrollView的OnTouchEvent吧。它特别允许您在scrollView注册运动事件时触发performClick()命令。似乎ScrollView会拦截所有的触摸事件,把它们当作运动事件,而不会让这些事件冒泡到任何父母身上。
这是有道理的。如果我正在触摸一个scrollView,我可能希望它是点击滚动视图中的某个东西,但我不希望它触发与scrollView父对象相关的东西。
https://stackoverflow.com/questions/11149404
复制相似问题