so what should be changed in adapter which populates new cards when a child is added in firebase,im sending data through an object of modal class.Now its only makes 1 card on which newly added data is updated on.No new cards are being populated.and i dont want to get the whole data again and again,i just wanted to get data only one time and it should be retreived when a child is added on because the admin has to approve the patients data(and then it should be removed thereafter).
myadapter
public class Adapter extends RecyclerView.Adapter<Adapter.Viewholder> {
public UserInformation value = new UserInformation();
public Adapter(UserInformation value) {
this.value = value;
}
@Override
public Viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.item_user_layout, parent, false);
return new Viewholder(view);
}
@Override
public void onBindViewHolder(Viewholder holder, int position) {
holder.edt_blood_group.setText(value.getBlood_group());
holder.edt_contact_no.setText(value.getContact_no());
holder.btn_approve.setText("approve");
}
@Override
public int getItemCount() {
return 3; //i dont know what to write here as i have no array of data
}
public class Viewholder extends RecyclerView.ViewHolder {
EditText edt_blood_group;
EditText edt_contact_no;
Button btn_approve;
public Viewholder(View itemView) {
super(itemView);
edt_blood_group = (EditText) itemView.findViewById(R.id.edt_blood_group);
edt_contact_no = (EditText) itemView.findViewById(R.id.edt_contact_no);
btn_approve = (Button) itemView.findViewById(R.id.btn_approve);
}
}
}
my MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RecyclerView rcc = (RecyclerView) findViewById(R.id.userList);
rcc.setLayoutManager(new LinearLayoutManager(this));
//edtobj= (EditText) findViewById(R.id.edt_id);
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference reference = firebaseDatabase.getReference("Patients");
reference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
UserInformation newPost = dataSnapshot.getValue(UserInformation.class);
rcc.setAdapter(new Adapter(newPost));
}
item_layout
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edt_blood_group"
android:layout_width="160dp"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edt_contact_no"
android:layout_width="160dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_approve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="approve" />
</LinearLayout>