我正在尝试在不单击任何按钮的情况下滑动多个活动。我只想用他们各自的活动刷屏。但是现在,我不能用活动刷屏。 在这里 我问看起来像这个问题。现在我只能搜索布局。我遵循 本教程。
描述
当我打开HotelDetails Activity时,我将它分为两部分,第一部分我们可以滑动,第二部分是列表视图。
在滑动部分我需要显示三个活动
1. HotelMap(滑动部分的主屏幕和前屏幕)
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)