How to bind ListView Objects in Fragments?

前端 未结 1 693
小蘑菇
小蘑菇 2021-01-28 21:25

I am having an issue binding my JSON data Object to a listView fragment. I\'m getting an NPE at line 100 where I bind to my Simple Adapter. I have tried various ways about doing

相关标签:
1条回答
  • 2021-01-28 22:23

    Unless you are omitting code you never assign the value of c or context.

    When calling

    SimpleAdapter adapter = new SimpleAdapter(c, mList, R.layout.list_item, from, to);
    

    You are passing in "c" which will always be null.

    switch "c" to getActivity() and the problem should go away

    Additionaly,

    final AQuery aq = new AQuery(c);
    

    You should initialize this once you know you have access to getActivity(). When a fragment is created it will not immediately have access to the activity until attach(..) is called.

    0 讨论(0)
提交回复
热议问题