Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

android - Not Getting Data From Firebase on ListView With FirebaseListAdapter

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...