java - How do i get the key UID of a node with a selected value in firebase database in android? -
below database in firebase
areas -areauid1 -admin -admin1uid -admin_name:"" -admin_area:"" -admin_email:"" -admin2uid -admin_name:"" -admin_area:"" -admin_email:"" . . -events -eventuid1 -event_name:"" -event_timings:"" -eventuid2 -event_name:"" -event_timings:"" . . -gallery -imageuid1 -image_link:"" -areauid2 -admin -admin1uid -admin_name:"" -admin_area:"" -admin_email:"" -admin2uid -admin_name:"" -admin_area:"" -admin_email:"" . . -events -eventuid1 -event_name:"" -event_timings:"" -eventuid2 -event_name:"" -event_timings:"" . . -gallery -imageuid1 -image_link:""
what want achieve?
i want areauid of areas considering fact there list of admin_areas available populated of same database. when user clicks on item in list want areauid of node admin_area matches selected admin_area list.
for eg) here list of areas presented user -
1)area 1
2)area 2
3)area 3
4)area 4
when user taps on area 2 want fetch areauid.how do this? below code reference
mdbref = firebasedatabase.getinstance().getreference().child("areas"); arr = new arraylist<>(); listview = (listview) findviewbyid(r.id.list_of_areas); valueeventlistener listener = new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { (datasnapshot snapshot : datasnapshot.getchildren()) { string areauid = snapshot.getkey(); log.i("areauid", areauid); showlistofareas(areauid); } } @override public void oncancelled(databaseerror databaseerror) { system.out.println(databaseerror.toexception()); } }; mdbref.addvalueeventlistener(listener); } private void showlistofareas(final string areauid) { pd.settitle("fetching registered areas"); pd.setmessage("loading areas..."); pd.show(); databasereference mareanameref = mdbref.getref().child(areauid).child("admin").child("admin1"); mareanameref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { final admin admin = datasnapshot.getvalue(admin.class); arr.add(admin.getadmin_colony()); adapter = new arrayadapter<>(listofareasactivity.this, android.r.layout.simple_list_item_1, android.r.id.text1, arr); listview.setadapter(adapter); pd.dismiss(); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string areaname = (string) parent.getitematposition(position); //finduseridwithlocation(areaname); sharedpreferences.editor editor = getsharedpreferences("shared_prefs", mode_private).edit(); editor.putstring("area_name", areaname); editor.apply(); editor.commit(); intent intent = new intent(listofareasactivity.this, mainactivity.class); startactivity(intent); finish(); } }); } @override public void oncancelled(databaseerror databaseerror) { } }); }
based on comment, areauid
can retrieved showlistofareas
's parameter
private void showlistofareas(final string areauid) { ... listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string areaname = (string) parent.getitematposition(position); // area's uid string areauidafterclick = areauid; sharedpreferences.editor editor = getsharedpreferences("shared_prefs", mode_private).edit(); editor.putstring("area_name", areaname); editor.apply(); editor.commit(); intent intent = new intent(listofareasactivity.this, mainactivity.class); startactivity(intent); finish(); } }); ... }
let me know if not meant.
Comments
Post a Comment