android - Firebase Delete -
i have 1 listview , adapter imagebutton delete data, don't know how delete data setonclick. need click imagebutton , delete data. have data type room not null.
public class orgmanageroom extends appcompatactivity { private listview listview; private arrayadapter<string> arrayadapter; private arraylist<string> list_of_rooms = new arraylist<>(); arraylist<hashmap<string, string>> myarrlist; public arraylist<string> arr; public arrayadapter adapter; private databasereference mdatabase = firebasedatabase.getinstance().getreference().getroot(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_org_manage_room); // listview = (listview)findviewbyid(r.id.listview); // listview.setadapter(new imageadapter(this)); // arrayadapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1,list_of_rooms); // listview.setadapter(arrayadapter); createadapter(); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent = new intent(orgmanageroom.this,orgadduser.class); startactivity(i); } }); } private void createadapter() { listview = (listview)findviewbyid(r.id.listview); listview.setadapter(new imageadapter(this)); mdatabase = firebasedatabase.getinstance().getreference().child("allroom"); mdatabase.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { set<string> set = new hashset<string>(); iterator = datasnapshot.getchildren().iterator(); while (i.hasnext()){ set.add(((datasnapshot)i.next()).getkey()); } list_of_rooms.clear(); list_of_rooms.addall(set); // arrayadapter.notifydatasetchanged(); } @override public void oncancelled(databaseerror databaseerror) { } }); } public class imageadapter extends baseadapter { private context context; public imageadapter(context c) { // todo auto-generated method stub context = c; } public int getcount() { // todo auto-generated method stub return list_of_rooms.size(); } public object getitem(int position) { // todo auto-generated method stub return position; } public long getitemid(int position) { // todo auto-generated method stub return position; } public view getview(final int position, view convertview, viewgroup parent) { // todo auto-generated method stub layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); if (convertview == null) { convertview = inflater.inflate(r.layout.deleteroom, null); } // colimgid textview txtposition = (textview) convertview.findviewbyid(r.id.colimgdesc); txtposition.setpadding(10, 0, 0, 0); txtposition.settext(list_of_rooms.get(position)); imagebutton cmdshared = (imagebutton) convertview.findviewbyid(r.id.imgcmdshared); cmdshared.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { toast.maketext(orgmanageroom.this, "test" + list_of_rooms.get(position), toast.length_long).show(); } }); return convertview; } } }
sorry, edit code , make project chat firebase , show listview listroom add user , delete user , manageroom. deletes room edit nameroom. same need click imagebutton delete listroom.
Comments
Post a Comment