NIKUNJ KHOKHAR NIKUNJ KHOKHAR - 11 months ago 110
Android Question

How to implement custom FirebaseAdapter for Listview?

I am using custom Adapter for implementing listview instead of default simple listview. Now, I want to add Firebase features to it for using Realtime database feature of it.

I know the steps to implement default FirebaseAdapter method, but how do I implement custom Adapter for listview using Firebase?

Code for simple FirebaseAdapter :

mRef = new Firebase("https://<myURL>..");
com.firebase.ui.FirebaseListAdapter<String> myAdapter;
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);

Answer Source

can do something like this :

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);


    }


}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download