set list view adapter in a fragment in android

后端 未结 2 1432
我在风中等你
我在风中等你 2021-02-07 19:12

I want a custom row, so I am using a List View in an xml and inflating into a fragment. I am very confused of how to set the adapter for the list View. I created a new adapter

相关标签:
2条回答
  • 2021-02-07 19:53

    If you do not want to change your extended class, you should use listview.setAdapter(...) method. As you see in my example :

    ListView productList= (ListView) getActivity().findViewById(R.id.product_list);
    
    
        SampleAdapter adapter = new SampleAdapter(getActivity());
    
    
        adapter.add(new SampleItem(
                "Sunny LCD TV 2\"  SN022L66-T1 Full HD",
                R.drawable.product_sample_pic);
    
    
        productList.setAdapter(adapter);
    
    0 讨论(0)
  • 2021-02-07 20:14

    You must extend Listfragment (instead of Fragment), and using its ListFragment.setListAdapter to set your adapter. In the adapter getView() inflate your row.. that s all

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