m.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/ViewPager"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/PagerTitleStrip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
>
</android.support.v4.view.PagerTitleStrip>
</android.support.v4.view.ViewPager>
</LinearLayout>
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
public class look extends Activity {
private ViewPager ViewPager;
private ArrayList<View> pageViews;
PagerTitleStrip PagerTitleStrip;
public ArrayList<String> lists2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.m);
LayoutInflater inflater=getLayoutInflater();
ViewPager=(ViewPager)this.findViewById(R.id.ViewPager);
PagerTitleStrip=(PagerTitleStrip)this.findViewById(R.id.PagerTitleStrip);
pageViews = new ArrayList<View>();
pageViews.add(inflater.inflate(R.layout.m1, null));
pageViews.add(inflater.inflate(R.layout.m2, null));
pageViews.add(inflater.inflate(R.layout.m3, null));
pageViews.add(inflater.inflate(R.layout.m4, null));
lists2= new ArrayList<String>();
lists2.add("标题1");
lists2.add("标题2");
lists2.add("标题3");
lists2.add("标题4");
ViewPager.setAdapter(new GuidePageAdapter());
}
/** Adapter */
class GuidePageAdapter extends PagerAdapter {
@Override
public int getCount() {
return pageViews.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
// TODO Auto-generated method stub
((ViewPager) arg0).removeView(pageViews.get(arg1));
}
@Override
public Object instantiateItem(View arg0, int arg1) {
// TODO Auto-generated method stub
((ViewPager) arg0).addView(pageViews.get(arg1));
return pageViews.get(arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
// TODO Auto-generated method stub
}
@Override
public CharSequence getPageTitle(int position) {
// TODO Auto-generated method stub
CharSequence s=null;
String k= lists2.get(position);
Log.v("ad", k);
s=(CharSequence)k;
return s;
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
}
}