For my app I have a base main activity, which holds a pageviewer.
In the activity class I have:
MyPagerAdapter adapter = new MyPagerAdapter(this);
viewPager.setAdapter(adapter);
The adapter class looks like:
private class MyPagerAdapter extends PagerAdapter {
private ArrayList<LinearLayout> views;
public MyPagerAdapter(Context context) {
views = new ArrayList<LinearLayout>();
views.add(new questionListView(context));
}
@Override
public void destroyItem(View view, int arg1, Object object) {
((ViewPager) view).removeView((LinearLayout) object);
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public int getCount() {
return views.size();
}
@Override
public Object instantiateItem(View view, int position) {
View myView = views.get(position);
((ViewPager) view).addView(myView);
return myView;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
}
}
}
The questionListView class looks like:
public class questionListView extends LinearLayout {
public questionListView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public questionListView(Context context) {
super(context);
init();
}
private void init() {
LayoutInflater factory = LayoutInflater.from(getContext());
View myView = factory.inflate(R.layout.view1,null);
addView(myView);
}
}
Main activity layout:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:alpha="4"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#000000" />
</android.support.v4.view.ViewPager>
view1 is a layout view, a linearlayout with other layouts in them.
When I run the app the main activity is shown, but the view with the view1-layout is not.
Why not, what am I doing wrong here?
I’m not getting any errors.
rg,
Eric
Luksprog help solved the problem.
Setting the PagerTitleStrip to wrap_content solved it.