'Solve a problem when pressing a button, more than one button is responded to
In a list of rows inside the recyclerview, I used the button operator to celebrate and appear every time I press it. I defined it to work inside the viewholder and the code works. But there is a problem when I press the first button. It and button number 18 are responded to at the same time. How do I avoid redundancy?
public void onBindViewHolder ( RecyclerViewAdapterBookA.catViewHolderBookA holder , int position ) {
BookA a = bookAS.get ( position );
holder.img.setImageResource ( a.getImg ( ) );
holder.text1.setText ( a.getText1 ( ) );
holder.text2.setText ( a.getText2 ( ) );
holder.img2.setImageResource ( a.getImg2 ( ) );
holder.img3.setImageResource ( a.getImg3 ( ) );
holder.img2.setTag ( 0 );
holder.img2.setOnClickListener ( new View.OnClickListener ( ) {
@Override
public void onClick ( View view ) {
final int status = (Integer) view.getTag ();
switch (status) {
case 0:
holder.img3.setVisibility ( View.VISIBLE );
Toast.makeText ( view.getContext ( ) , "تم تعليمه گ مقروء" , Toast.LENGTH_SHORT ).show ( );
view.setTag ( 1 );
break;
case 1:
holder.img3.setVisibility ( View.INVISIBLE );
Toast.makeText ( view.getContext ( ) , "تم تعليمه گ غير مقروء" , Toast.LENGTH_SHORT ).show ( );
view.setTag ( 0 );
break;
}
}
} );
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
