Simple Listview in fragment using SimpleAdapter

后端 未结 3 347
深忆病人
深忆病人 2021-01-20 09:16

Here is my code for fragment extending ListFragment and below are the errors it is showing.Almost Same code is working fine for activity except that in activity i am getting

相关标签:
3条回答
  • 2021-01-20 10:12

    Try this way,hope this will help you to solve your problem.

    There is two way to given ListView id.

    1.android predefined id like :

    XML

    <ListView
       android:id="@android:id/list"
    

    Activty

    lv= (ListView) findViewById(android.R.id.list);
    

    Fragment

    lv= (ListView)rootView.findViewById(android.R.id.list); 
    

    2.Custom id like :

    XML

    <ListView
       android:id="@+id/list"
    

    Activty

    lv= (ListView) findViewById(R.id.list);
    

    Fragment

    lv= (ListView)rootView.findViewById(R.id.list); 
    
    0 讨论(0)
  • 2021-01-20 10:12

    try this.

    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.soundcloud, container, false);
    

    and also in your onItemClick

    // Starting single contact activity

    Intent in = new Intent(getActivity().getApplicationContext(),
                       SingleContactActivity.class);
              in.putExtra("name", TAG_TITLE);
              in.putExtra("id", cost);
              startActivity(in);
    
    0 讨论(0)
  • 2021-01-20 10:18

    Try using this code to get your ListView:

    ListView lv = (ListView) getActivity().findViewById(android.R.id.list);
    

    As you are using a ListFragment as the base class. Also you probably would need to use android.R.id.list to get your list if you put it correctly in your xml file.

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