Firebase Android Development, Update ListView -



Firebase Android Development, Update ListView -

first off, i'm sorry if has been asked before.

so partner , creating firebase linked app android. firebase looks this:

+ projects + <some project> +name: <name> +users +<a user> +<another user> + <another project> + users + <some user> + <another user>

the problem in our app, user logins firebase, found in users child, , there listview populated projects part of (i.e. projects' users contains user logging in.)

the login works fine, , listview works fine when hard code in projects, when have find projects, displays empty list, because info isn't returned before listview created.

here code have far: our login activity code:

public class loginactivity extends activity implements loadercallbacks<cursor> { /** * maintain track of login task ensure can cancel if requested. */ // private userlogintask mauthtask = null; private progressdialog mauthprogressdialog; /* reference firebase */ private firebase ref = new firebase(<url>); /* info authenticated user */ private authdata authdata; /* tag used logging statements */ private static final string tag = "logindemo"; // ui references. private autocompletetextview memailview; private edittext mpasswordview; private view mprogressview; private view mloginformview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); firebase.setandroidcontext(this); setcontentview(r.layout.activity_login); mauthprogressdialog = new progressdialog(this); mauthprogressdialog.settitle("loading"); mauthprogressdialog.setmessage("authenticating firebase..."); mauthprogressdialog.setcancelable(false); // set login form. memailview = (autocompletetextview) findviewbyid(r.id.email); populateautocomplete(); mpasswordview = (edittext) findviewbyid(r.id.password); mpasswordview .setoneditoractionlistener(new textview.oneditoractionlistener() { @override public boolean oneditoraction(textview textview, int id, keyevent keyevent) { if (id == r.id.login || id == editorinfo.ime_null) { attemptlogin(); homecoming true; } homecoming false; } }); button memailsigninbutton = (button) findviewbyid(r.id.email_sign_in_button); memailsigninbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { attemptlogin(); } }); mloginformview = findviewbyid(r.id.login_form); mprogressview = findviewbyid(r.id.login_progress); } private void populateautocomplete() { getloadermanager().initloader(0, null, this); } /** * attempts sign in or register business relationship specified login form. * if there form errors (invalid email, missing fields, etc.), * errors presented , no actual login effort made. */ public void attemptlogin() { // if (mauthtask != null) { // return; // } // reset errors. memailview.seterror(null); mpasswordview.seterror(null); // store values @ time of login attempt. string email = memailview.gettext().tostring(); string password = mpasswordview.gettext().tostring(); boolean cancel = false; view focusview = null; //email , password validity checking //i.e. email have @ , password longer 4 characters? if (cancel) { // there error; don't effort login , focus first // form field error. focusview.requestfocus(); } else { // show progress spinner, , kick off background task // perform user login attempt. showprogress(true); mauthprogressdialog.show(); loginwithpassword(email, password); showprogress(false); } } public void openprojectlistview(authdata authdata) { arraylist<project> projects = new arraylist<project>(); user user = new user( <url>+"users/" + authdata.getuid()); map<project, role> projectmap = user.getprojects(); (project p : projectmap.keyset()) { projects.add(p); } //arrayadapter<project> arrayadapter = new arrayadapter<project>(this, // android.r.layout.simple_list_item_activated_1, // android.r.id.text1, projects); // setlistadapter(arrayadapter); //listchangenotifier<project> lcn = new listchangenotifier<project>( // arrayadapter); //for (project project : projects) { // project.setlistchangenotifier(lcn); //} mauthprogressdialog.hide(); intent intent = new intent(this, projectlistactivity.class); intent.putparcelablearraylistextra("projects", projects); this.startactivity(intent); } private void setauthenticateduser(authdata authdata) { if (authdata != null) { string name = authdata.getuid(); this.authdata = authdata; openprojectlistview(this.authdata); } } public void loginwithpassword(string username, string password) { ref.authwithpassword(username, password, new authresulthandler( "password")); } private class authresulthandler implements firebase.authresulthandler { private final string provider; public authresulthandler(string provider) { this.provider = provider; } @override public void onauthenticated(authdata authdata) { setauthenticateduser(authdata); } @override public void onauthenticationerror(firebaseerror firebaseerror) { showerrordialog(firebaseerror.tostring()); } } private void showerrordialog(string message) { new alertdialog.builder(this).settitle("error").setmessage(message) .setpositivebutton(android.r.string.ok, null) .seticon(android.r.drawable.ic_dialog_alert).show(); }

this our project list activity code:

public class projectlistactivity extends activity implements projectlistfragment.callbacks { public user user; /** * whether or not activity in two-pane mode, i.e. running on tablet * device. */ private boolean mtwopane; /** * list of projects */ private arraylist<project> projects; /** * selected project */ private project projectitem; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.projects = this.getintent() .getparcelablearraylistextra("projects"); boolean tabletsize = (getresources().getconfiguration().screenlayout & configuration.screenlayout_size_mask) >= configuration.screenlayout_size_large; if (!tabletsize) { setcontentview(r.layout.activity_project_list); } else { setcontentview(r.layout.activity_project_twopane); } if (findviewbyid(r.id.project_detail_container) != null) { // detail container view nowadays in // large-screen layouts (res/values-large , // res/values-sw600dp). if view present, // activity should in two-pane mode. this.mtwopane = true; // in two-pane mode, list items should given // 'activated' state when touched. ((projectlistfragment) getfragmentmanager().findfragmentbyid( r.id.project_list)).setactivateonitemclick(true); } } @override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == android.r.id.home) { // id represents home or button. in case of // activity, button shown. utilize navutils allow users // navigate 1 level in application structure. // more details, see navigation pattern on android design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // finish(); homecoming true; } homecoming super.onoptionsitemselected(item); } /** * * @return */ public arraylist<project> getprojects() { homecoming projects; } /** * callback method {@link projectlistfragment.callbacks} indicating * item given id selected. */ public void onitemselected(project p) { this.projectitem = p; if (this.mtwopane) { // in two-pane mode, show detail view in activity // adding or replacing detail fragment using // fragment transaction. bundle arguments = new bundle(); // arguments.putstring(projectdetailfragment.arg_item_id, id); arguments.putparcelable("project", p); projectdetailfragment fragment = new projectdetailfragment(); fragment.setarguments(arguments); getfragmentmanager().begintransaction() .replace(r.id.project_detail_container, fragment).commit(); } else { // in single-pane mode, start detail activity // selected item id. intent detailintent = new intent(this, projectdetailactivity.class); // detailintent.putextra(projectdetailfragment.arg_item_id, id); detailintent.putextra("project", p); startactivity(detailintent); } }

}

and lastly, here our listchangenotifier code:

public class listchangenotifier<t> { private arrayadapter<t> adapter; public listchangenotifier(arrayadapter<t> adapter) { this.adapter = adapter; } /** * * method triggered when info changed in object. * */ public void onchange() { this.adapter.notifydatasetchanged(); }

}

i'm sorry include much code, i'm not sure people need see.

thanks help!

edit:

here's code project list fragment deals adapter:

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //this.projects = this.getarguments().getparcelablearraylist("projects"); this.projects = ((projectlistactivity)this.getactivity()).getprojects(); // done: replace real list adapter. arrayadapter<project> arrayadapter = new arrayadapter<project>(getactivity(), android.r.layout.simple_list_item_activated_1, android.r.id.text1, this.projects); setlistadapter(arrayadapter); listchangenotifier<project> lcn = new listchangenotifier<project>(arrayadapter); (project project : this.projects) { project.setlistchangenotifier(lcn); } }

android listview android-listview firebase firebase-android

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -