我已将我的代码分段,以便遵循oop概念,因此在四个活动中出现的代码被制作成它自己的单独活动。现在这个子活动动作取决于它被调用的四个父活动中的哪一个..所以setContent视图值根据父活动而变化..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pdf_view);
Intent intent = getIntent();
String url = intent.getStringExtra("URL");
答案 0 :(得分:1)
我明白了......
你所要做的就是在setcontentview方法之前调用oncreate函数中的intent ..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String url = intent.getStringExtra("URL");
String layout = intent.getStringExtra("layout");
int id =getResourceUsingName(layout,"layout");
setContentView(id);
}
private int getResourceUsingName(String name, String type) {
mContext=getApplicationContext();
Resources resources = mContext.getResources();
int resourceId = resources.getIdentifier(name, type,
mContext.getPackageName());
return resourceId;
}