0

I have my firebase list adapter as follows

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    mListview = (ListView) findViewById(R.id.listview);

    mAuth = FirebaseAuth.getInstance();
    //the post list shit is happening here

    DatabaseReference root = FirebaseDatabase.getInstance().getReference();
    FirebaseUser user = mAuth.getCurrentUser();
    DatabaseReference postRef = root.child("users").child(user.getUid().toString()).child("posts");

    ListAdapter adapter = new FirebaseListAdapter<PostList>(this,PostList.class,android.R.layout.simple_list_item_1,postRef) {
        @Override
        protected void populateView(View view, PostList postList, int i) {
            TextView text = (TextView)view.findViewById(android.R.id.text1);
            text.setText(postList.getBody());

        }

    };
    mListview.setAdapter(adapter);

I have a normal xml with a list view and another xml with its card view

my problem is that i cannot find a way to relate my cardview xml file to my activity, so my list just keep showing up as a normal list, While initializing the firebase list adapter, I found an R.layout_simple_list_item im not sure exactly how that works and i have googled, nothing explains definitely why i cant just say R_layout_my_card_view_xmlinstead. Also, please let me know if i am going about this all wrong.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mordred
  • 185
  • 2
  • 15
  • 1
    If you are using CardView I suggest you use FirebaseRecyclerAdapter instead. – Linxy Aug 19 '16 at 07:13
  • Can you point me to any good tutorial that specifically deals with recycler adapter from firebase location and not some static array – Mordred Aug 19 '16 at 09:12
  • Install the FirebaseRecyclerAdapter from Here: https://github.com/firebase/FirebaseUI-Android and then there is a full tutorial aswell: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md – Linxy Aug 19 '16 at 09:17
  • Thank you. seems useful. – Mordred Aug 19 '16 at 09:28
  • one more question, is it safe to edit R.layouts like simple list items directly – Mordred Aug 19 '16 at 09:34
  • 1
    If you make your own R.layout.simple_list_item, then you can style and edit it like you want. However, i don't think you can directly edit the android.R.layout.simple_list_item layouts. – Linxy Aug 19 '16 at 09:41

1 Answers1

0

I got the answer to this already, Just in case anyone is going through the same problem, just as Linxy clearly stated, it is better to use FirebaseRecyclerAdapter, it is a modified version of the ListAdapter.

However if you feel like you still want to use a ListAdapter, then:

  1. First note that you cannot directly edit android.R.layout.items, instead create your own layout, say you have row.xml in your layout files, use R.layout.row as your populateView() arguments and not android.R.layout.row, the latter wont find anything because those layout files are stored in your SDK folder.

  2. Please, consider the recycler adapter, its not that hard.

Sufian
  • 6,405
  • 16
  • 66
  • 120
Mordred
  • 185
  • 2
  • 15