I have used a Viewpager for horiantal swiping of images which are present inside drawable folder i have used http://idroidsoftwareinc.blogspot.in/2013/06/android-viewpager-swipe-images-using.html this link now i have another int array of image for which i have used the same code now i just want to switch between another viewpager on button click so that I can access the images(for Swiping) from that viewPager. PLEASE HELP ME? I am stuck... I have referred this links How to get several ViewPagers into a ScrollView?
Asked
Active
Viewed 358 times
0
-
If I understand it right, wouldn't it work for you if you load the new set of pages/images in the existing ViewPager when you click the button? – Stan Feb 20 '14 at 10:00
-
hey Stan I took two viewpager in my XMl and done the corrosponding code for their apperence. now i just wanted to change the viewpager on button click – Abhi Feb 20 '14 at 10:09
-
How about hiding one view pager and showing the other? (by setting their Visibility to View.GONE and View.VISIBLE respectively) Have you tried that? – Stan Feb 20 '14 at 10:18
-
NO Please give me the source – Abhi Feb 20 '14 at 10:22
-
OK, I'll write an answer for you in a few minutes – Stan Feb 20 '14 at 10:36
1 Answers
0
One way of doing this is hiding the first ViewPager and showing the second one.
From what you are saying it seems that you have the two view pagers in the same layout, something like this (I am giving a simplified version just to illustrate!):
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="@+id/view_pager1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
In your Activity you need to get a reference to these view pagers, which I assume you have already. And then in the OnClickListener of your button change the visibility of the view pagers:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // This is the name of you layout file
final ViewPager viewPager1 = (ViewPager) findViewById(R.id.view_pager1);
final ViewPager viewPager2 = (ViewPager) findViewById(R.id.view_pager2);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewPager1.setVisibility(View.GONE);
viewPager2.setVisibility(View.VISIBLE);
}
});
// ...
}

Stan
- 2,151
- 1
- 25
- 33
-
Thank You Dear its so simple .....Yeahhhhhhhhhhhhhhhhhhhh You have solved my problem thanks a lot..... – Abhi Feb 20 '14 at 10:58
-
I'm glad. Could you select my answer as The Answer to you question then? :) – Stan Feb 20 '14 at 11:21