in Education by
I wish to retrieve my the elements inside Users that as a field of ArrayList and display each schedule object and its fields in a recyclerview. I have used the model , adapter pattern that most people used but i do not know how to retrieve data for the "schedule" because it is nested. I get an error saying recycler view no adpater attach. I have tried doing this public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view =inflater.inflate(R.layout.fragment_schedule,container,false); final ArrayList schedulelist = new ArrayList<>(); firebaseDatabase=firebaseDatabase.getInstance(); myRef=firebaseDatabase.getReference("Users").child(userID); recyclerView= view.findViewById(R.id.my_recycler_view); recyclerView.setHasFixedSize(true); mLayoutman= new LinearLayoutManager(getActivity()); madapter= new ScheduleAdapter(schedulelist); FirebaseUser user = firebaseAuth.getCurrentUser(); userID = user.getUid(); myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { for (DataSnapshot ds : dataSnapshot.getChildren()) { User user = new User(); user = ds.getValue(User.class); ArrayList scheduleItems = user.getSchedule(); for (int i = 0; i < scheduleItems.size(); i++) { Parent = scheduleItems.get(i).getParent_N(); Kid = scheduleItems.get(i).getKid_N(); Time = scheduleItems.get(i).getTime(); Date= scheduleItems.get(i).getDate(); Place= scheduleItems.get(i).getPlace(); schedulelist.add(new ScheduleItem(Parent, Kid, Time,Date,Place)); Log.d(TAG, "onDataChange: "); } recyclerView.setAdapter(madapter); recyclerView.setLayoutManager(mLayoutman); } } @Override public void onCancelled(@NonNull DatabaseError databaseError) { System.out.print("Failed"); } }); return view; } } and here is my adapter //formatted code public class ScheduleAdapter extends RecyclerView.Adapter { private ArrayList displaylist; public static class ScheduleViewHolder extends RecyclerView.ViewHolder{ private TextView Parent_name; private TextView Kid_name; private TextView Time; private TextView Date; private TextView Place; public ScheduleViewHolder(@NonNull View itemView) { super(itemView); Parent_name = itemView.findViewById(R.id.s_parent); Kid_name=itemView.findViewById(R.id.s_kid); Time=itemView.findViewById(R.id.s_time); Date=itemView.findViewById(R.id.s_date); Place=itemView.findViewById(R.id.s_place); } } public ScheduleAdapter(ArrayList list) { this.displaylist=list; } @NonNull @Override public ScheduleViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.schedule_item,viewGroup,false); ScheduleViewHolder x= new ScheduleViewHolder(view); return x; } @Override public void onBindViewHolder(@NonNull ScheduleViewHolder scheduleViewHolder, int i) { ScheduleItem current=displaylist.get(i); scheduleViewHolder.Parent_name.setText(current.getParent_N()); scheduleViewHolder.Kid_name.setText(current.getKid_N()); scheduleViewHolder.Time.setText(current.getTime()); scheduleViewHolder.Date.setText(current.getDate()); scheduleViewHolder.Place.setText(current.getPlace()); } @Override public int getItemCount() { return displaylist.size(); } } here is my schedule model` public class ScheduleItem { private String Parent_N; private String Kid_N; private String Time; private String Date; private String Place; public ScheduleItem(String parent_N, String kid_N, String time, String date, String place) { Parent_N = parent_N; Kid_N = kid_N; Time = time; Date = date; Place = place; } public String getParent_N() { return Parent_N; } public void setParent_N(String parent_N) { Parent_N = parent_N; } public String getKid_N() { return Kid_N; } public void setKid_N(String kid_N) { Kid_N = kid_N; } public String getTime() { return Time; } public void setTime(String time) { Time = time; } public String getDate() { return Date; } public void setDate(String date) { Date = date; } public String getPlace() { return Place; } public void setPlace(String place) { Place = place; } } ` and my user model public class User { private User userObject; public String email, username, userType; public ArrayList schedule; public User(){ } public User(String email){ this.email = email; } public User(String email, String username, String userType) { this.email = email; this.username = username; this.userType = userType; } public User(String email, String username, String userType, ArrayList scheduleIN) { this.email = email; this.username = username; this.userType = userType; this.schedule=scheduleIN; } public String getEmail() { return email; } public String getUsername() { return username; } public void setEmail(String email) { this.email = email; } public void setUsername(String username) { this.username = username; } public String getUserType() { return userType; } public void setUserType(String userType) { this.userType = userType; } public ArrayList getSchedule() { return schedule; } public void setSchedule(ArrayList scheduleIN) { this.schedule = scheduleIN; } } here is my database JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I get an error saying recycler view no adpater attach. Try: recyclerView.setAdapter(madapter);

Related questions

0 votes
    I'm currently trying Firebase Remote Config on Android. I gave a parameter a value: 2.2 but when ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Write a program to accept a filename from the user and display all the lines from the file which contain python comment character ‘#’. Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    Which of these method of ArrayList class is used to obtain present size of an object? (a) size() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Unlike writing out a table or CSV file, dump() and dput() preserve the ______ so that another user ... Operations of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Create a view named customer mobile details which has the following attributes Display customer istomer name mobile ... ascending order Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
0 votes
    WAP to display all the information of student (like name, class, roll no) in qbasic Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    I've managed to read some values into a table view and display them in the Master View of a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am writing a program to optimize a transportation system. I have an ArrayList "passengers" of 65,000 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am writing a program to optimize a transportation system. I have an ArrayList "passengers" of 65,000 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    When two threads access the same ArrayList object what is the outcome of the program? (a) Both are able ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these method can be used to increase the capacity of ArrayList object manually? (a) Capacity() ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of these methods can be used to obtain a static array from an ArrayList object? (a) Array() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    How can we remove an object from ArrayList? (a) remove() method (b) using Iterator (c) remove() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
...