例如:
Intent intent = new Intent(SinglePlayer.this,jump01.class);
startActivity(intent);
Intent intent = new Intent(SinglePlayer.this,jump02.class);
startActivity(intent);
Intent intent = new Intent(SinglePlayer.this,jump03.class);
startActivity(intent);
Intent intent = new Intent(SinglePlayer.this,jump04.class);
startActivity(intent);
问题,我想把上面intent跳转时候的(jump01,jump02,jump03,jump04)里面的数字用一个变量代替了得怎么做?
答:使用工厂模式的一种,
intent = new Intent( SinglePlayer.this, Class.forName("xin.Beerhero.zhangjian.jump"+ index));
startActivity(intent);
//注:xin.Beerhero.zhangjian是你的包名,jump 是你所要跳转到的类的名字
// 接受传过来的地图参数,设置对应参数的地图
setContentView(getResources().getIdentifier( "map" + MapGallery.sentpositon, "layout","xin.Beerhero.zhangjian"));
= setContentView(R.layout.map0);