刷卡活动有问题

时间:2013-01-07 11:10:19

标签: android android-activity swipe

我正在尝试使用多个活动进行滑动而不点击任何按钮。我只是想用各自的活动刷屏幕。但是现在,我无法用活动刷屏幕。 Here我问这个问题。 现在我只能搜索布局。我关注this tutorial。 的描述
当我打开HotelDetails Activity时,我将它分为两​​部分,我们可以滑动,第二部分是列表视图 在滑动部分我需要显示三个活动
1.酒店地图(刷卡部分的主屏幕和前屏幕)
2. hotelAddress(向左滑动)
3. hotelContact(向右滑动)。

这是我的代码,但它只会滑动屏幕而不是活动。

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;
}

}

我在showHotelMap中使用注释代码,但它显示了以下异常

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)

1 个答案:

答案 0 :(得分:0)

MapView必须存在于MapActivity中。你不能把它放在ViewPager中。但是,您可以使用支持片段的新版Google Maps Android API v2。 您仍然需要处理水平滑动问题(例如,当您在地图页面上时,如何区分地图平移手势和页面更改手势?)。

另见: https://developers.google.com/maps/documentation/android/v1/hello-mapview

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