android - How to populate a ListView using a FirebaseListAdapter? -
i working on android project, allow users find nearest petrol pump's name, address, , importantly prices. have listview, want populate through firebase list adapter because using firebase project. after writing code getting nothing firebase -- it's blank screen on android phone (no error showing in android studio).
after writing setcontentview(lview); in end of oncreate() method , giving me error , activity crashes. got error firebase : com.firebase.client.firebaseexception: failed bounce type
import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.listview; import android.widget.textview; import com.firebase.client.firebase; import com.firebase.ui.firebaselistadapter; public class testbezinpriser extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // setcontentview(r.layout.activity_testbezinpriser); listview lview = new listview(this); firebase.setandroidcontext(this); firebase ref = new firebase("https://xxxxx.firebaseio.com"); firebaselistadapter<benzin> adapter = new firebaselistadapter<benzin>(this, benzin.class, r.layout.listepriser, ref) { @override protected void populateview(view v, benzin s, int i) { ((textview)v.findviewbyid(r.id.navnview)).settext(s.getname()); ((textview)v.findviewbyid(r.id.addressview)).settext(s.getaddress()); ((textview)v.findviewbyid(r.id.prisview)).settext(s.getprice())); } }; lview.setadapter(adapter); setcontentview(lview); } }
and benzin class
public class benzin { string address; string name ; string price; public benzin(){ } public benzin (string name , string address , string price){ this.name = name; this.address = address; this.price = price; } public string getaddress(){ return address; } public string getname(){ return name; } public string getprice(){ return price; }
}
xml layout listepriser
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <imageview android:layout_width="80dp" android:layout_height="50dp" android:id="@+id/logoview" android:layout_alignparenttop="true" android:layout_alignparentstart="true" android:layout_margintop="20dp" android:src="@drawable/shell" android:contentdescription="tankstation_billed" /> <textview android:layout_width="70dp" android:layout_height="25dp" android:id="@+id/navnview" android:layout_aligntop="@+id/logoview" android:layout_toendof="@+id/logoview" android:layout_marginstart="10dp" android:textstyle="bold|italic" android:textsize="15sp" android:textcolor="#000000" android:text="shell" android:layout_margintop="5dp" android:textisselectable="false" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="måløvhovedgade 38 , måløv" android:id="@+id/addressview" android:layout_alignbottom="@+id/logoview" android:layout_alignstart="@+id/navnview" android:layout_marginbottom="3dp" android:textsize="12sp" android:textcolor="#000000" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="10.99" android:id="@+id/prisview" android:layout_aligntop="@+id/navnview" android:layout_alignparentend="true" android:layout_marginright="10dp" android:textcolor="#000000" android:typeface="serif" />
if @ full stack trace of failed bounce type
exception, tell wrong.
but in case seems problem caused fact property names in json start uppercase letter. work:
public class benzin { public string address; public string name ; public string price; }
Comments
Post a Comment