2011-10-21 2 views
1

파일을 선택할 대화 상자가 있습니다. 이 대화 상자에는 디렉토리 및 파일을 표시하는 listview가 있으며 탐색 목적으로 onItemClickListener가 있습니다.전체 대화 상자의 Android onTouchListener

플링 이벤트에 어떻게 대응하여 디렉토리 구조에 올라갈 수 있습니까?

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()에 등록 얻을하지만 onFling() 메소드가 MyGestureDetector에 호출되지 않습니다 : 파견 내 GestureListener에 터치 이벤트에 나는 루트 RelativeLayout의 상 OnTouchListener를 설정했습니다. 그러나 OnTouchListener를 listview에 첨부하면 예상대로 작동합니다. 이 방법의 문제점은 목록 뷰가 항상 데이터로 가득 채워져 있지 않으며 비어 있거나 항목 아래를 클릭하면 onTouch() 이벤트가 트리거되지 않는다는 것입니다.

대화 레이아웃 : 완전히 작성되지 lisview와 대화에 대한

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

스크린 샷 : http://imageshack.us/photo/my-images/802/dialog.png/

은 어떻게 onFling을() 이벤트가 전체 대화 또는 "전체"목록보기에서 트리거 할 수 있습니다 항목으로 완전히 채워지지 않은 경우에도?

감사합니다.

답변

5

당신은 대화 상자 클래스를 확장하는 클래스를 작성해야하며, 다음 제스처 검출기를 만들 수 있습니다 및 클래스의 ontouchevent에 연결하기위한 터치 이벤트를 얻었다. 다음은 코드 예입니다.

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; 
    } 
} 

} 
0

activity 한 개를 가져와 dialog의 매니 페스트에있는 theme으로 설정할 수 있습니다.

그런 다음 해당 활동에 에 implements onTouchListener을 기록하고 해당 활동에 onTouch() 이벤트를 작성하십시오.

이제 전체 대화 :