0

I have an activity which works as a pager. In this activty there are some fragments, and a ListView. Is it possible that I set the list adapter on my activity from one of my fragments?

4

3 回答 3

0

Why don't you use ViewPager instead of inveting all by yourself. Follow the link and you will find example on using this android feature. Also, it's backward-compatible using the support library.

If it helps you what to do ;)

于 2013-01-14T09:00:23.313 回答
0

You can access the Activity that holds the Fragment by calling getActivity() after onActivityCreated() in the Fragments lifecycle.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);
  ListView lv = (ListView) getActivity().findViewById(R.id.your_list_view);
  lv.setAdapter(yourAdapter);
}
于 2013-01-14T09:02:48.230 回答
0

You need to use ListAdapter for that. Have a look here

于 2013-01-14T09:03:25.657 回答