Skip to content Skip to sidebar Skip to footer

Toast Gets Intent Data Why Doesn't Cardview In Recyclerview?

I have a user input Activity that passes EditText data back to a RecyclerView list of CardViews. Everything is working fine except for one problem. After I've created the first Ca

Solution 1:

Too much complication. Let us make it simple. The problem seems to be within onActivityResult in pushing data to the list.

Kindly change the snippet as below.

Initially Declare the Custom List and Custom Adapter globally. (In your case : Contact )

AdapterContactList conAdapter;
List<Contact> conList;

In onCreate Initialize your list and add empty list to the adapter and attach it to RecyclerView.

conList= new ArrayList<>();
conAdapter= newAdapterContactList (this, conList);
recyclerView.setAdapter(conAdapter);

Then in your onActivityResult do it as below.

if (resultCode == RESULT_OK && requestCode == 101) {
  StringdoMessage= data.getStringExtra("MESSAGE1");
  StringdoMessage1= data.getStringExtra("MESSAGE2");
  Contactcon=newContact(doMessage, doMessage1);
  conList.add(con);
  conAdapter.notifyDataSetChanged();
}

That's it, Now you will see the data populating correctly in the recycler view. And Hope your Recyclerview Adapter and rest of the part is working fine in this case.

Queries let me know.

Post a Comment for "Toast Gets Intent Data Why Doesn't Cardview In Recyclerview?"