0

I'd like to programmatically create ImageViews inside a RecyclerView list of CardViews in my app. At the moment, each CardView had a + button which upon onClick adds the item in the CardView to a database.

I'd like to replace the + button with a checkmark image, to indicate to the user that the item in question has been added to the database. I'd also like to include two other ImageViews on an added CardView item: a delete button and and edit button, to allow the user to delete or edit the item respectively.

Is this something I'll need to do in my custom adapter? Should I be creating a separate XML layout file with the edit/delete buttons and inflate that layout within a new, programatically-created ImageView?

I've already replaced the + image with a checkmark, using the setImageResource() method within my item's setOnClickListener() method, but I know this isn't the correct solution: this just replaces the image within the existing ImageView.

sourav.bh
  • 467
  • 1
  • 7
  • 20
James Whelan
  • 91
  • 1
  • 7

1 Answers1

0
 LayoutParams params = new LayoutParams(
                    LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT
            );
  ImageView img = new ImageView(this);
  img.setLayoutParams(params);
  card.addview(img);
Hesam Rasoulian
  • 1,356
  • 3
  • 12
  • 18
  • Thanks for your code. I'd already tried something similar to this but keep getting null object errors on the ImageView. – James Whelan Mar 22 '19 at 21:53