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?
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 ;)
You can access the Activity
that holds the Fragment
by calling getActivity()
after onActivityCreated()
in the Fragment
s lifecycle.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ListView lv = (ListView) getActivity().findViewById(R.id.your_list_view);
lv.setAdapter(yourAdapter);
}
You need to use ListAdapter
for that. Have a look here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.