-
Notifications
You must be signed in to change notification settings - Fork 4k
Are fragments required? PageAdapter not working #38
Comments
Fragments are not required. In fact, ViewPagerIndicator doesn't care what's in the actual pager at all. You could use anything. Fragments, views, or whatever other fancy whowhatsit you can shove into a I personaly have never used If you end up figuring it out I'm sure another sample would be welcome to demonstrate that to others. |
Will do. I worked back from the example into what is now a mess, but just plain PageAdapter. If I can't make progress in getting something visible, will post the code with a proper issue if there is something not working. Just wanted to make sure before dug in to deep with regular ol' view adapter |
The views show up without fragments, but not sure why the tabs aren't showing (w/halo, etc). package com.viewpagerindicator.sample;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.viewpagerindicator.TabPageIndicator;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;
/**
* Created by IntelliJ IDEA.
* User: rich
* Date: 12/16/11
* Time: 9:39 PM
* To change this template use File | Settings | File Templates.
*/
public class SimpleTabActivity extends Activity {
private static final String[] CONTENT = new String[]{"Recent", "Artists", "Albums", "Songs", "Playlists", "Genres"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs);
PagerAdapter mAdapter = new ImagePagerAdapter();
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
TabPageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
class ImagePagerAdapter extends PagerAdapter implements TitleProvider {
public int getCount() {
return CONTENT.length;
}
public String getTitle(int position) {
return CONTENT[position];
}
public Object instantiateItem(View collection, int position) {
Context c = SimpleTabActivity.this.getApplicationContext();
LinearLayout l = new LinearLayout(collection.getContext());
l.setOrientation(LinearLayout.HORIZONTAL);
l.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
l.setPadding(0,50,0,0);
ImageView v = new ImageView(c);
v.setImageDrawable(c.getResources().getDrawable(R.drawable.icon));
l.addView(v);
TextView tv = new TextView(c);
tv.setText(CONTENT[position]);
l.addView(tv);
((ViewPager) collection).addView(l, 0);
return l;
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((LinearLayout) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((LinearLayout) object);
}
/**
* Called when the a change in the shown pages has been completed. At this
* point you must ensure that all of the pages have actually been added or
* removed from the container as appropriate.
*
* @param container The containing View which is displaying this adapter's
* page views.
*/
@Override
public void finishUpdate(View arg0) {
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
}
} |
I just took this example: http://blog.stylingandroid.com/archives/537 and changed the TitlePage indicator to a TabPage Indicator and see the exact same issue. The halo/text/styles don't work. |
I've tried to use the pageadapter and it just shows blank views. I have the examples compiling fine, but switching to use a PagerAdapter to return the view for the position is creating a valid view, yet I get a blank page...
The text was updated successfully, but these errors were encountered: