0

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)
Community
  • 1
  • 1
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

1 Answers1

0

MapView has to live inside a MapActivity. You cannot put it in a ViewPager. You can, however, use the new Google Maps Android API v2, which supports Fragments. You still have to deal with horizontal swiping issue though (i.e. when you are on the map page, how do you differentiate between a map pan gesture and a page change gesture?).

See also: https://developers.google.com/maps/documentation/android/v1/hello-mapview

and

https://developers.google.com/maps/documentation/android/

katzoft
  • 858
  • 8
  • 10