I am trying to swipe with multiple activity without clicking on any button. I just want to swipe screen with their respective activities.But Right now, I am not able to swipe screen with activities. Here i ask look like this question.
Now i am able to search only layout. I follow this tutorial.
Description
When i open HotelDetails Activity, I divide it into two part first we can swipe and second part is list view.
In Swipe part i need to show three activities
1. HotelMap(Main and front Screen of Swipe part)
2. hotelAddress(Swipe to left)
3. hotelContact(Swipe to right).
Here is my code but it will only swipe screen not activities.
MyPagerAdapter adapter = new MyPagerAdapter();
myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(3);
private class MyPagerAdapter extends PagerAdapter {
public int getCount(){
return 3;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = showHotelContact();
break;
case 1:
resId = showHotelAddress();
break;
case 2:
resId=showHotelMap();
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
// TODO Auto-generated method stub
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View arg0) {
// TODO Auto-generated method stub
}
}
public int showHotelMap()
{
i need to swipe activity therfore i use commented code but not able
// Intent bookIntent = new Intent();
// bookIntent.setClass(HotelMap.this,ShowMap.class);
// startActivity(bookIntent);
// ShowMap showmap = new ShowMap();
int resId = R.layout.hoteladdress;
return resId;
}
public int showHotelAddress()
{
int resId;
resId = R.layout.hoteladdress;
TextView tvAddress = (TextView)findViewById(R.id.tvHotelAddress);
tvAddress.setText(address);
return resId;
}
public int showHotelContact()
{
int resId;
resId = R.layout.hotelcontact;
return resId;
}
}
I use commented code in showHotelMap but it showing Following Exception
01-07 17:38:12.993: E/AndroidRuntime(10442): android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
01-07 17:38:12.993: E/AndroidRuntime(10442): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-07 17:38:12.993: E/AndroidRuntime(10442): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-07 17:38:12.993: E/AndroidRuntime(10442): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-07 17:38:12.993: E/AndroidRuntime(10442): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-07 17:38:12.993: E/AndroidRuntime(10442): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-07 17:38:12.993: E/AndroidRuntime(10442): at com.programr.dishoom.HotelMap$MyPagerAdapter.instantiateItem(HotelMap.java:134)