我有一个对话框可以从中选择文件。此对话框包含一个用于显示目录和文件的列表视图,并具有一个用于导航目的的 onItemClickListener。
我如何对在目录结构中上升的事件做出反应?我尝试在根 RelativeLayout 上设置 OnTouchListener 以将触摸事件分派到我的 GestureListener:
final GestureDetector detector = new GestureDetector(new MyGestureDetector(tvCurrentPath));
dialog.findViewById(R.id.rlFilelist).setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent e) {
detector.onTouchEvent(e);
return false;
}
});
事件在 onTouch() 中注册,但从未在 MyGestureDetector 中调用 onFling() 方法。但是,如果我将 OnTouchListener 附加到列表视图,它会按预期工作。这种方法的问题是列表视图并不总是大量填充数据,当它为空或单击下面的项目时,不会触发 onTouch() 事件。
对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlFilelist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:focusable="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/llButtons" >
<TextView
android:id="@+id/tvCurrentPath"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
</TextView>
<ListView
android:id="@+id/lvFileListing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/llButtons"
android:layout_below="@id/tvCurrentPath" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/llButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip" >
<Button
android:id="@+id/btAddDirectory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10px"
android:text="@string/host_tv_dg_add_directory" />
<Button
android:id="@+id/btUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:layout_toRightOf="@id/btAddDirectory"
android:text="@string/host_tv_dg_navigate_up" />
<Button
android:id="@+id/btClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/btUp"
android:text="@string/_tv_close" />
</RelativeLayout>
</RelativeLayout>
未完全填充 lisview 的对话框的屏幕截图:http: //imageshack.us/photo/my-images/802/dialog.png/
如何使 onFling() 事件在整个对话框或“整个”列表视图上触发,即使它没有完全填充项目?
谢谢!