2016-12-13 1 views
0

RecyclerView에서 ImageButton을 사용하고 있습니다. 응용 프로그램에서 ClickListener를 처리하려고합니다.이 코드는 ViewHolder의 코드입니다.RecyclerView의 ImageButton 문제

저는 FirebaseUI를 사용하고 있으므로 어댑터는 FirebaseRecyclerAdapter입니다.

RecyclerView가 올바르게 표시되지만 ImageButton을 클릭해도 아무런 변화가 없습니다.

무엇이 문제입니까? 나는 또한이 같은 populateViewHolder() 내부의 리스너를 사용하려

public class PicturesHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 

     Context context; 
     ImageButton imageButtonView; 
     TextView textIDView; 
     TextView latitudeView; 
     TextView longitudeView; 
     TextView dateView; 

     public PicturesHolder(View itemView) { 
      super(itemView); 
      this.context = itemView.getContext(); 
      imageButtonView = (ImageButton) itemView.findViewById(R.id.image); 
      textIDView = (TextView)itemView.findViewById(R.id.texto); 
      latitudeView=(TextView) itemView.findViewById(R.id.latitude); 
      longitudeView = (TextView) itemView.findViewById(R.id.longitude); 
      dateView = (TextView) itemView.findViewById(R.id.dateView); 

      itemView.setOnClickListener(this); 
      imageButtonView.setOnClickListener(this); 

     } 

     public void setImage(String url) { 
      Glide.with(context) 
        .load(url) 
        .into(imageButtonView); 
     } 

     public void setTextIDView(String textID) { 
      textIDView.setText(textID); 
     } 

     public void setLatitude(double latitude) 
     { 
      latitudeView.setText(String.valueOf(latitude)); 
     } 
    public void setLongitude(double longitude) 
    { 
     longitudeView.setText(String.valueOf(longitude)); 
    } 

    public void setDateView(String date) 
    { 
     dateView.setText(date); 
    } 

    @Override 
    public void onClick(View v) { 
      Toast.makeText(v.getContext(), "Item Pressed = " + String.valueOf(getAdapterPosition()), Toast.LENGTH_SHORT); 
    } 
} 

:

이 viewHolder의 코드 마지막으로

public void onAttachRecyclerView() { 

    //Query lastHundred = mURLReference.limitToLast(100); 
    Query mQuery = mURLReference.orderByChild("date").limitToLast(100); 
    mRecyclerViewAdapter = new FirebaseRecyclerAdapter<Pictures, PicturesHolder>(

      Pictures.class,R.layout.item_row,PicturesHolder.class, mQuery 

    ) { 
     @Override 
     protected void populateViewHolder(PicturesHolder viewHolder, Pictures model, final int position) { 
      viewHolder.setTextIDView(model.getPictureID()); 
      viewHolder.setImage(model.getDownloadURL()); 
      viewHolder.setLatitude(model.getLatitude()); 
      viewHolder.setLongitude(model.getLongitude()); 
      viewHolder.setDateView(model.getDate()); 

      viewHolder.imageButtonView.setOnClickListener(new View.OnClickListener(){ 
       @Override 
       public void onClick(View view){ 
        Toast.makeText(view.getContext(), "You clicked on " + position, Toast.LENGTH_SHORT); 
       } 
      }); 
     } 
    }; 
    mImagesRV.setAdapter(mRecyclerViewAdapter); 

} 

,이 항목 뷰의 XML은 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="0.5"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/texto"/> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 

     <ImageButton 
       android:src="@color/tw__composer_deep_gray" 
       android:layout_gravity="center" 
       android:padding="20dp" 
       android:layout_marginBottom="2dp" 
       android:layout_marginLeft="2dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginTop="2dp" 
       android:layout_height="300dp" 
       android:layout_width="300dp" 
       android:id="@+id/image" 
       android:layout_weight="0.39" /> 

     <TextView 
      android:text="Coordenadas:" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView" 
      android:textAppearance="@style/TextAppearance.AppCompat.Body2" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/latitude"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/longitude"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/espacioBlanco" 
      android:text=" "/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/dateView" 
      /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/orderNumber"/> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/darker_gray"/> 
    </android.support.v7.widget.CardView> 

</LinearLayout> 

인사말!

+0

에 표시()를 호출하는 것을 잊었다 작동 생각? –

+0

@SauravGhimire done :) XML을 추가했습니다 –

답변

2

나는 모든 것이 예상대로, 당신은 당신이 항목보기의 XML을 추가 할 수 토스트 객체

Toast.makeText(..).show(); 
+0

고마워요! 나는 그 세부 사항을 보지 못했다 ... –