• <bdo id='zcoNv'></bdo><ul id='zcoNv'></ul>
      1. <tfoot id='zcoNv'></tfoot>
        <i id='zcoNv'><tr id='zcoNv'><dt id='zcoNv'><q id='zcoNv'><span id='zcoNv'><b id='zcoNv'><form id='zcoNv'><ins id='zcoNv'></ins><ul id='zcoNv'></ul><sub id='zcoNv'></sub></form><legend id='zcoNv'></legend><bdo id='zcoNv'><pre id='zcoNv'><center id='zcoNv'></center></pre></bdo></b><th id='zcoNv'></th></span></q></dt></tr></i><div id='zcoNv'><tfoot id='zcoNv'></tfoot><dl id='zcoNv'><fieldset id='zcoNv'></fieldset></dl></div>

        <legend id='zcoNv'><style id='zcoNv'><dir id='zcoNv'><q id='zcoNv'></q></dir></style></legend>

        <small id='zcoNv'></small><noframes id='zcoNv'>

        整个对话框的Android onTouchListener

        时间:2023-08-30

          <bdo id='tAALr'></bdo><ul id='tAALr'></ul>

          <small id='tAALr'></small><noframes id='tAALr'>

            <tfoot id='tAALr'></tfoot>
          1. <legend id='tAALr'><style id='tAALr'><dir id='tAALr'><q id='tAALr'></q></dir></style></legend>
              <tbody id='tAALr'></tbody>

                <i id='tAALr'><tr id='tAALr'><dt id='tAALr'><q id='tAALr'><span id='tAALr'><b id='tAALr'><form id='tAALr'><ins id='tAALr'></ins><ul id='tAALr'></ul><sub id='tAALr'></sub></form><legend id='tAALr'></legend><bdo id='tAALr'><pre id='tAALr'><center id='tAALr'></center></pre></bdo></b><th id='tAALr'></th></span></q></dt></tr></i><div id='tAALr'><tfoot id='tAALr'></tfoot><dl id='tAALr'><fieldset id='tAALr'></fieldset></dl></div>

                • 本文介绍了整个对话框的Android onTouchListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个对话框可以从中选择文件.此对话框包含一个用于显示目录和文件的列表视图,并具有一个用于导航目的的 onItemClickListener.

                  I have a dialog to choose files from. This dialog contains a listview to show directories and files and has an onItemClickListener for navigation purposes.

                  我如何对在目录结构中上升的投掷事件做出反应?我尝试在根 RelativeLayout 上设置 OnTouchListener 以将触摸事件发送到我的 GestureListener:

                  How can I react to fling events to go up in the directory structure? I tried setting an OnTouchListener on the root RelativeLayout to dispatches touch events to my 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() 事件.

                  The events get registered in onTouch(), but the onFling() method is never called in the MyGestureDetector. If, however, I attach the OnTouchListener to the listview, it works as expected. The problem with this approach is that the listview is not always filled extensively with data and when it is empty or when clicking below items, no onTouch() events are triggered.

                  对话框布局:

                      <?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/

                  Screenshot for dialog with not completely filled lisview: http://imageshack.us/photo/my-images/802/dialog.png/

                  如何使 onFling() 事件在整个对话框或整个"列表视图上触发,即使它没有完全填充项目?

                  How can I make the onFling() events trigger on the whole dialog or on the "whole" listview even when it's not completely filled with items?

                  谢谢!

                  推荐答案

                  您应该创建一个扩展对话框类的类,然后您可以创建一个手势检测器并附加到该类的 ontouchevent.这是一个代码示例:

                  You should create a class which extends the dialog class and then you can create a gesture detector and attach to the ontouchevent of the class. Here is a code example:

                  public class GestureDialog extends Dialog {
                      public GestureDialog (Context context, int theme) {
                          super(context, theme);
                  
                          gestDetec = new MyGestureDetector();    //inital setup
                          gestureDetector = new GestureDetector(gestDetec);   
                          gestureListener = new View.OnTouchListener() {
                              public boolean onTouch(View v, MotionEvent event) {
                                  if (gestureDetector.onTouchEvent(event)) {
                                      return true;
                                  }
                                  return false;
                              }
                          };
                      }
                      @Override
                      public boolean onTouchEvent(MotionEvent event) {
                          if (gestureDetector.onTouchEvent(event))
                              return true;
                          else
                              return false;
                      }
                  class MyGestureDetector extends SimpleOnGestureListener {
                      @Override
                      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                  
                          System.out.println( "Help im being touched!" );
                          return false;
                      }
                  }
                  
                  }
                  

                  这篇关于整个对话框的Android onTouchListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在自定义对话框中创建正面和负面按钮 下一篇:在自定义对话框中设置微调器

                  相关文章

                  最新文章

                • <i id='z3Dpp'><tr id='z3Dpp'><dt id='z3Dpp'><q id='z3Dpp'><span id='z3Dpp'><b id='z3Dpp'><form id='z3Dpp'><ins id='z3Dpp'></ins><ul id='z3Dpp'></ul><sub id='z3Dpp'></sub></form><legend id='z3Dpp'></legend><bdo id='z3Dpp'><pre id='z3Dpp'><center id='z3Dpp'></center></pre></bdo></b><th id='z3Dpp'></th></span></q></dt></tr></i><div id='z3Dpp'><tfoot id='z3Dpp'></tfoot><dl id='z3Dpp'><fieldset id='z3Dpp'></fieldset></dl></div>
                  • <bdo id='z3Dpp'></bdo><ul id='z3Dpp'></ul>

                    <legend id='z3Dpp'><style id='z3Dpp'><dir id='z3Dpp'><q id='z3Dpp'></q></dir></style></legend>

                    <tfoot id='z3Dpp'></tfoot>

                      <small id='z3Dpp'></small><noframes id='z3Dpp'>