2013-08-31 4 views
0

좋아, 두 개의 ImageButton이 있고 정확히 동일하게 설정했지만 PLAY 만 onClick 수신기로 호출됩니다. 다른 하나를 클릭하면 등록되지 않은 것입니다. 디버깅 할 때 findViewById가 객체를 올바른 뷰와 모든 것에 등록하고 있음을 보여줍니다. 나는 여전히 touchevent를 얻지 만 Close 버튼은 내 OnClick 메서드에 나타나지 않습니다. 아마 xml 파일은이 버그에서 역할을하고 있습니다. 왜냐하면 나는 일어날 수있는 다른 것을 생각할 수 없기 때문입니다.OnClick 하나의 ImageButton에 대해서만 작동합니다.

조각 코드

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 

    View v = inflater.inflate(R.layout.playback_frag, container, false); 

    //BUTTONS 
    close = (ImageButton) v.findViewById(R.id.x_close); 
    play = (ImageButton) v.findViewById(R.id.play1); 

    btnListener = new OnClickListener(){ 
     @Override 
     public void onClick(View v){ 
      Log.e("in btnListener", "howdy"); 
     } 
    }; 

    close.setOnClickListener(btnListener); 
    play.setOnClickListener(btnListener); 


    return v; 
} 

XML 레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="166dp" 
    android:background="#D8000000" 
    > 
    <!-- Start of title bar --> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

      <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="38dp" 
      android:weightSum="1" 
      android:background="#CC33b5e5" > 

     <TextView android:id="@+id/playback_title" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:textSize="14sp" 
        android:gravity="center_vertical" 
        android:textAllCaps="true" 
        android:paddingLeft="6dp" 
        android:textColor="#FFFFFF" 
        android:layout_weight=".4" 
        /> 



       <TextView android:id="@+id/playback_sample_rate" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:textColor="#FFFFFF" 
        android:textSize="12sp" 
        android:paddingLeft="16dp" 
        android:gravity="center_vertical"   
        android:layout_weight=".2" 
        /> 

       <TextView android:id="@+id/playback_file_size" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:textColor="#FFFFFF" 
        android:textSize="12sp" 
        android:gravity="center_vertical"      
        android:paddingLeft="16dp" 
        android:layout_weight=".2" 
        /> 

        <ImageButton android:id="@+id/x_close" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingLeft="16dp" 
        android:background="#00000000" 
        android:layout_gravity="center_vertical" 
        android:src="@android:drawable/ic_menu_close_clear_cancel" 
        android:gravity="center_vertical" 
        /> 
       </LinearLayout> 
    </LinearLayout> 
    <!-- End of title bar --> 

     <!--start of details --> 
     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height = "118dp" 
      android:layout_alignParentTop="true" 
      android:paddingTop="44dp" 
      > 
      <TextView android:id="@+id/playback_details" 
       android:paddingRight="6dp" 
       android:paddingLeft="6dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       /> 
     </ScrollView> 


     <!--end of details --> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:layout_marginBottom="16dp" 
     > 
      <!-- Start of slider --> 
      <LinearLayout android:id="@+id/sliderANDplay" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="32dp"> 

        <ImageButton 
         android:id="@+id/play1" 
         android:layout_marginLeft="12dp" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:background="#80000000" 
         android:padding="5dp" 
         android:scaleX=".80" 
         android:scaleY=".80" 
         android:src="@drawable/av_play" /> 

        <SeekBar 
          android:id="@+id/slider1" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:max="60" 
          android:progress="0" 
          android:secondaryProgress="0" /> 
      </LinearLayout> 
      <!-- End of slider --> 

      <!-- Start of times --> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="32dp" 
       android:gravity="right|bottom" 
       > 


         <TextView 
          android:id="@+id/curr_pos1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:paddingRight="1dp" 
          android:text="@string/init_time_curr" 
          android:textColor="#ffffff" 
          android:textSize="12sp" /> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="/" 
          android:textColor="#ffffff" 
          android:paddingRight="1dp" 
          android:textSize="11sp" /> 

         <TextView 
          android:id="@+id/max_duration1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginRight="17dp" 
          android:text="@string/init_time_max" 
          android:textColor="#ffffff" 
          android:textSize="12sp" /> 

       </LinearLayout> 
      <!-- End of times --> 


    </RelativeLayout> 
당신은 하나 (각 버튼의 하나)을 두 개의 별도 onClickListeners을 만들거나 하나의 어느 버튼을 눌렀는지 확인해야

답변

0

청취자.

btnListener = new OnClickListener(){ 
    @Override 
    public void onClick(View v){ 

     if (v.getID == R.id.x_close) 
      Log.e("in btnListener", "howdy"); 
     else if (v.getID == R.id. play1) 
     // do something else 
    } 
}; 
+0

바로 그게 내가 일을 계획하고,하지만 난 닫기 버튼을 클릭하면 심지어는 클릭 된 것을 온 클릭 리스너에 등록하지 않는거야. –

+0

이상한. 다음에 개별 청취자에게 노력해 봤어? – pumpkee

+0

개별 청취자가 프래그먼트에서 'OnClickListener'를 구현 한 다음 그렇습니다 (그리고 나서'setOnClickListener (this);'를 수행하는 경우) –

관련 문제