java - Fetching data from firebase taking more than one button click to display -
i want display data fetched firebase whenever user clicks button. code using currently
todaypoem = (textview) findviewbyid(r.id.todpoem); /*firebase related code*/ myfirebaseref = new firebase("https://firebase url"); myfirebaseref.child("poem").addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot snapshot) { system.out.println(snapshot.getvalue()); s1 = (string) snapshot.getvalue(); } @override public void oncancelled(firebaseerror error) { } }); } public void onclickpoem(view v) { todaypoem.settextsize(20); todaypoem.settext(s1); }
and xml file contains textview , button fetch data firebase. problem whenever click button data not displayed instantly, takes 5-6 button clicks data displayed. doing wrong here?
i had problem before... advice doing example:
mrf.setandroidcontext(this); mrf = new firebase('firebase url'); final firebase mydata = mrf.child("info"); mydata.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(final datasnapshot datasnapshot) { x1 = datasnapshot.getvalue(string.class); x2 = x1; // global variable } @override public void oncancelled(firebaseerror firebaseerror) { } });
use variable 'x2' want. don't why there problem using same variable used receive data firebase.
hope work you...
also if user know data being retrieve can use progressbar handler. after button clicked , 'x1' equals null this: progressbar.setvisibility(view.visible);
then
handler.postdelayed(new runnable() { public void run() { progressbar.setvisibility(view.gone); t.settext(x2); } }, 800);
good luck..
Comments
Post a Comment