I have tried to create a custom PagerAdapter
since I want to show some pages, where each page contains a ListView
, that should be initialized by the pager adapter constructor MyPagerAdapter
, that receives the Activity
where the ViewPager
is used, and a list of Strings entries
.
The problem is that setAdapter(myListAdapter)
called on the ListView
seems ineffective and listview appears empty.
Here the piece of code where I try to initialize the ListView
:
public class MyPagerAdapter extends PagerAdapter {
...
public MyPagerAdapter( Activity activity, ArrayList<String> entries){
mContext = activity.getBaseContext();
inflater = LayoutInflater.from(mContext);
ViewGroup viewGroup = (ViewGroup) activity.findViewById(R.id.pager);
View v=inflater.inflate(R.layout.page1, viewGroup);
ListView page_1_list = (ListView) v.findViewById(R.id.page_1_list);
mylistAdapter = new ArrayAdapter(mContext, R.layout.spinner_item, entries);
page_1_list.setAdapter(mylistAdapter);
}
....
}
Could someone explain me why happens this and how could I fix the error?
- The entries list isn't empty.
- The
ViewPager
has several pages but here I'm showing only the list relative to the first page. - The issue has nothing to do with the xml since if I try to fill It directly from the activity works.
- I'm able to google myself ViewPager tutorials. The question is related to a problem, and the answer should be related to the problem itself. So if your answer doesn't explain WHY listView cannot be filled with items with described approach It is off-topic and I will not accept It.