android - How to use Firebase List adapter -


i'm trying follow tutorial:

https://www.youtube.com/watch?v=2j6spwavp0m

but implementing on complex app didn't work tried scratch..

i created simple mainactivity:

public class mainactivity extends appcompatactivity{      firebase mref;     com.firebase.ui.firebaselistadapter<string> myadapter;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         mref = new firebase("https://<myurl>..");          myadapter = new firebaselistadapter<string>(this,string.class,android.r.layout.simple_list_item_1,mref) {             @override             protected void populateview(view view, string s, int i) {                 textview text = (textview)view.findviewbyid(android.r.id.text1);                 text.settext(s);              }         };         button addbtn = (button) findviewbyid(r.id.add_button);         addbtn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 mref.push().setvalue("test123");             }         });     } } 

now have few questions:

1) triggers populateview? couldn't make run

2) should android.r.layout.simple_list_item_1 replaced with? tried creating own listview , replace above r.id.listview nothing happens.. can't figure out how magic works..

3) simple app didn't work.. button add "test123" right place on server see nothing on app.. whats wrong?

i found out wrong, missing listview.. heres corrected code:

public class mainactivity extends appcompatactivity {      firebase mref;     com.firebase.ui.firebaselistadapter<string> myadapter;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         mref = new firebase("https://<myurl>..");          myadapter = new firebaselistadapter<string>(this,string.class,android.r.layout.simple_list_item_1,mref) {             @override             protected void populateview(view view, string s, int i) {                 textview text = (textview) view.findviewbyid(android.r.id.text1);                 text.settext(s);             }         };         final listview lv = (listview) findviewbyid(r.id.listview);         lv.setadapter(myadapter);          button addbtn = (button) findviewbyid(r.id.add_button);         addbtn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 mref.push().setvalue("test123");             }         });     }   } 

the lv.setadapter associating adapter list , triggers populateview.. that's answer of 3 questions @ once..

here xml well:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.twodwarfs.firebaselistadapter.mainactivity">       <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="add"         android:id="@+id/add_button"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true" />      <listview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/listview"         android:layout_tostartof="@+id/add_button"         android:layout_below="@+id/textview" /> </relativelayout> 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo