android - Storing data in Firebase -


i have trouble storing data in firebase. want store link , date (from previous fragment) in firebase database.

i can store link date not seem stored in database on click of fab. appreciated , relevant code below:

public class details extends appcompatactivity {  private static final string key_link = "link";  requestqueue requestqueue;  public static final int connection_timeout = 10000; public static final int read_timeout = 15000;  private recyclerview rv; private cardview cardview; floatingactionbutton fab; private boolean ischecked = true;  private list<detail> detaillist = new arraylist<>();  private vibrator vib;  private firebase firebaseref;  private static final string firebase_url = "https://athenajs.firebaseio.com";   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_details);     toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);          firebase.setandroidcontext(this);          intent in = getintent();          firebaseref = new firebase(firebase_url).child("favourites");      //         json values previous intent         final string link = in.getstringextra(key_link);         final string date = in.getstringextra("date");          final favclick mfav = new favclick(link, date);          final string pushid = firebaseref.push().getkey();          vib = (vibrator) this.getsystemservice(vibrator_service);         cardview = (cardview) findviewbyid(r.id.cv);         rv = (recyclerview) findviewbyid(r.id.rv);           fab = (floatingactionbutton) findviewbyid(r.id.fab);         fab.settag(1);         fab.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view view) {                  final int status = (integer) view.gettag();                 if (status == 1) {                     fab.setimageresource(r.drawable.ic_favorite_white_48dp);                     snackbar.make(view, "added favourites!", snackbar.length_long)                             .setaction("action", null).show();                     view.settag(0);                      firebaseref.child(pushid).setvalue(mfav);                  } else {                     fab.setimageresource(r.drawable.ic_favorite_border_white_48dp);                     snackbar.make(view, "removed favourites!", snackbar.length_long)                             .setaction("action", null).show();                     view.settag(1);                     firebaseref.child(pushid).removevalue(null);                 }               }          }); 

try this:

firebase favref = firebaseref.child("favourites");  map<string, string> data = new hashmap<string, string>(); data.put("date", date); data.put("link", link); favref.push().setvalue(data); 

in fab onclickmethod.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -