3

제목에서 말했듯이, 나는 scrollclock을 듣고 있어야하지만, 잡는 중이다. scrollview- 로그가없고 햅틱 피드백이 없으면 & 대화 상자가 표시되지 않습니다.안드로이드 Scrollview 잡기 longclick

미리 감사드립니다.

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> 

+0

코드에 OnTouchListener 또는 OnClickListener가 있습니까? OnLongClickListener의 프로세스를 중단시킬 수 있습니다. 메소드의 반환 값에주의하십시오. – Davidsun

+0

tabHost가 자체적으로 생성하지 않는 한 -이 클래스의 다른 수신기는 내 OnTabChangedListener()뿐입니다. – bhekman

+0

추가 작업을 수행 한 결과 동일한 리스너가 scrollview에 포함 된 textview에 대해 잘 작동한다는 것을 알았습니다. 두 명의 리스너를 만들고 싶지는 않습니다. 아무도 이것을 설명 할 수 있습니까 ?? – bhekman

답변

6

잘 나는 내 문제의 정확한 소스 확인되지 않았다, 그러나 나는 청취자와 충돌 어떤 종류의 의심이 스크롤 뷰는 자체 스크롤을 필요로합니다.

이 문제는 scrollview 대신에 linearlayout에서 똑같은 수신기를 설정하여 해결했습니다. 단순한. 희망이 도움이됩니다!

+0

매우 이상하고 왜 OnLongClickListener가 LinearLayout과 완벽하게 잘 동작하는지 알 수는 없지만 ScrollView : – PCoder

0

ScrollView의 OnTouchEvent을 확인하십시오. 특히 scrollView가 모션 이벤트를 등록 할 때 performClick() 명령을 실행할 수 있습니다. ScrollView는 모든 터치 이벤트를 가로 채고 모션 이벤트로 처리하며 모든 부모에게 클릭 한 번으로 이벤트를 표시하지 않습니다.

어떤 의미가 있습니다. scrollView를 만지면 scrollview 내부의 내용을 클릭하는 것이 좋지만 scrollView의 부모와 관련된 내용은 트리거하지 않아야합니다.

관련 문제