top of page
Writer's pictureCodersarts AI

Retrieving list data from firebase inside Current User_Id

Firebase is Google's mobile application development platform that helps you build, improve, and grow your app. Here it is again in bigger letters, for impact: Firebase is Google's mobile application development platform that helps you build, improve, and grow your app




  • Creating Models

The Android framework manages the lifecycles of UI controllers, such as activities and fragments. The framework may decide to destroy or re-create a UI controller in response to certain user actions or device events that are completely out of your control.

DataUser.java


public class DataUser {

public DataUser(String course, String date, String status, String time, String mob) {

Course = course;

Date = date;

Status = status;

Time = time;

this.mob = mob;

}


public String getCourse() {

return Course;

}


public void setCourse(String course) {

Course = course;

}


public String getDate() {

return Date;

}


public void setDate(String date) {

Date = date;

}


public String getStatus() {

return Status;

}


public void setStatus(String status) {

Status = status;

}


public String getTime() {

return Time;

}


public void setTime(String time) {

Time = time;

}


public String getMob() {

return mob;

}


public void setMob(String mob) {

this.mob = mob;

}


private String Course;

private String Date;

private String Status;

private String Time;

private String mob;


public DataUser()

{


}


}

  • Creating List_Adapter

  • What is Adapter

Adapter is a bridge between UI component and data source that helps us to fill data in UI component. It holds the data and send the data to an Adapter view then view can takes the data from the adapter view and shows the data on different views like as ListView, GridView,


ListAdapter.java

public class ListAdapter extends ArrayAdapter {

private Activity context;

List<DataUser> studentlist;

public ListAdapter (Activity context, List<DataUser> studentlist)

{

super(context, R.layout.item_group, studentlist );

this.context=context;

this.studentlist=studentlist;


}


@NonNull

@Override

public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {


LayoutInflater inflater=context.getLayoutInflater();

View listviewitem=inflater.inflate( R.layout.item_group,null,true);

TextView mob = listviewitem.findViewById( R.id.mob );

TextView course = listviewitem.findViewById( R.id.Course );

TextView date = listviewitem.findViewById( R.id.Date );

TextView time = listviewitem.findViewById( R.id.Time );

TextView status = listviewitem.findViewById( R.id.Status );

DataUser dataUser = studentlist.get( position );

mob.setText( dataUser.getMob() );

course.setText( dataUser.getCourse() );

date.setText( dataUser.getDate());

time.setText( dataUser.getTime() );

status.setText( dataUser.getStatus() );

return listviewitem;

}

}

Activity for Fetching Data


public class SessionBooked extends AppCompatActivity

{

TextView mob, Course, Date, Time, Status;

ListView listView;

List<DataUser> dataUserList;

DatabaseReference databaseReference;

ImageView back;

ArrayList<String> arrayList = new ArrayList<>();

ArrayAdapter<String> arrayAdapter;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate( savedInstanceState );

setContentView( R.layout.activity_session_booked );

back=findViewById( R.id.back );

listView=findViewById( R.id.list );

dataUserList=new ArrayList<>();


back.setOnClickListener( new View.OnClickListener() {

@Override

public void onClick(View v) {

finish();

}

} );

String userID = FirebaseAuth.getInstance().getCurrentUser().getUid();

databaseReference=FirebaseDatabase.getInstance().getReference("LiveSession").child( userID );

databaseReference.addListenerForSingleValueEvent( new ValueEventListener() {

@Override

public void onDataChange(@NonNull DataSnapshot snapshot) {

dataUserList.clear();

for (DataSnapshot ds:snapshot.getChildren())

{

DataUser user=ds.getValue(DataUser.class);

dataUserList.add( user );

}

ListAdapter adapter=new ListAdapter( SessionBooked.this,dataUserList );

listView.setAdapter( adapter );


}


@Override

public void onCancelled(@NonNull DatabaseError error) {


}

} );


output :





Hire an android developer to get quick help for all your android app development needs. with the hands-on android assignment help and android project help by Codersarts android expert. You can contact the android programming help expert any time; we will help you overcome all the issues and find the right solution.

Want to get help right now? Or Want to know price quote

CONTACT NOW










20 views0 comments

Recent Posts

See All

Comments


bottom of page