Reputation: 18120
I'm trying to implement a viewPager to display an array of strings (that contains three strings). I'm trying to look up a tutorial on how I would go about something like this, but it seems that I need to use a ViewPager with fragments. Isn't there a simple was to use a ViewPager without involving fragments?
Again, I'm following the developer docs: http://developer.android.com/training/animation/screen-slide.html
But, I don't necessarily want to make the entire screen move over. I'd only like for the bottom 1/3 of my screen to swipe. Can anyone confirm that this is possible to do without fragments? Or is there another view I should use (horizontal Scroll View)
EDIT:
So I was doing something right. I was trying to use a ViewPager and a pagerAdapter but my application crashes. Anything glaringly broken about my code?
ViewPager mPager;
setContentView(R.layout.activity_convo_detail);
PagerAdapter mAdapter = new PagerAdapter() {
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 3;
}
};
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
Upvotes: 2
Views: 1462
Reputation: 17284
You don't need Fragment
s for ViewPager
, Have a look : http://androidtrainningcenter.blogspot.com/2012/10/viewpager-example-in-android.html
And for your second Question, this is how you take 1/3 of space:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2" />
<android.support.v4.view.ViewPager
android:id="@+id/myfivepanelpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Upvotes: 3
Reputation: 3349
Fragments aren't that heavy, or complicated. I don't think they are overkill for this.
However, you can use a PagerAdapter without using fragments.
A ViewPager can page plain old TextViews if that is what you want.
Basically, you don't have to use FragmentPagerAdapter. Your PagerAdapter can take an array of Strings and return just a view for each.
Upvotes: 1