Simple Listview in fragment using SimpleAdapter

无人久伴 提交于 2019-12-01 21:18:32

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

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.

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!