Ich habe die RecyclerView mit Bild, Titel und Kontrollkästchen ausgefüllt. Ich habe zwei Probleme.Holen Sie sich die Liste der markierten Kontrollkästchen von recyclerview android
Wie Sie das Kontrollkästchen aktiviert machen, wenn der Imageview oder das gesamte Recycler Element geklickt wird.
Ich muss zur nächsten Aktivität gehen, indem ich alle geprüften Artikel aus der Recycler-Ansicht abrufe.
Mein Layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:contentDescription="Interests"
android:scaleType="centerCrop"
android:src="@drawable/ic_yash_dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:layout_marginTop="24dp"
android:background="@drawable/rounded_corners"
android:gravity="bottom"
android:padding="5dp"
android:text="GYM"
android:textAlignment="center"
android:textColor="@color/white" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox"
android:layout_margin="2dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Mein Adapter:
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
final InterestBean model = arrayList.get(position);
final int pos = position;
RecyclerViewHolder mainHolder = (RecyclerViewHolder) holder;// holder
Bitmap image = BitmapFactory.decodeResource(context.getResources(),
model.getImage());// This will convert drawbale image into bitmap
// setting title
mainHolder.title.setText(model.getTitle());
mainHolder.imageview.setImageBitmap(image);
mainHolder.checkBox.setChecked(arrayList.get(position).isSelected());
mainHolder.checkBox.setTag(arrayList.get(position));
mainHolder.checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
InterestBean contact = (InterestBean) cb.getTag();
contact.setIsSelected(cb.isChecked());
arrayList.get(pos).setIsSelected(cb.isChecked());
selectedItems.add(pos);
Toast.makeText(
v.getContext(), pos + cb.isChecked(), Toast.LENGTH_LONG).show();
}
});}
Das ist einfach unglaublich, Leute benutzen bitte diese Lösung! –