The Problem with this code is that the data is not showing in listview and the app is also not showing any error. I am initializing this model class from some other activity, so please any one can give me suggestion about what would be the real problem.
public class FireBaseListAdapter extends AppCompatActivity {
private ListView mlistview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_base_list_adapter);
mlistview = (ListView)findViewById(R.id.firebase_list);
// DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
final Query query = getInstance().getReference();
FirebaseListOptions<Users> options = new FirebaseListOptions.Builder<Users>().setQuery(query,Users.class).setLayout(R.layout.listview_for_firebaselistadapter).build();
FirebaseListAdapter<Users> firebaseListAdapter = new FirebaseListAdapter<Users>(options) {
@Override
protected void populateView(View v, Users model, int position) {
model = getItem(position);
TextView textViewname = (TextView)v.findViewById(R.id.listAdapter_nametext);
TextView textViewplace = (TextView)v.findViewById(R.id.listAdapter_placetext);
textViewname.setText(model.getName());
textViewplace.setText(model.getPlace());
}
};
mlistview.setAdapter(firebaseListAdapter);
}
}
This is My Model Class:
public class Users {
private String name;
private String place;
public Users() {
}
public Users(String name, String place) {
this.name = name;
this.place = place;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
}
This is My XML containing two textView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/listAdapter_nametext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver Name"
android:textSize="25sp"/>
<TextView
android:id="@+id/listAdapter_placetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver Place"
android:textSize="25sp"/>
</LinearLayout>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…