我在这里的目的是将“ibChamp”的图片从默认图片更改为“ahri”。请注意,*** 内的名称是 Activity 的名称。
***CreateBuilds.java***
ibChamp.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent champs = new Intent(CreateBuilds.this, Champions.class);
//creates the Intent champs for startActivityForResult()
startActivityForResult(champs, 0);
//opens up Champions.class layout
}
});
protected void onActivityResult(int requestCode, int resultCode, int data){
//starts when this.finish() from Champions is ran
ImageButton ibChamp = (ImageButton) findViewById(R.id.ibChamp);
//creates the ImageButton ibChamp
ibChamp.setImageResource(R.drawable.ahri);
//sets the picture of ibChamp to "ahri"
};
***Champions.java****
private myapplicationtest mytestInst = new myapplicationtest();
public void changePicture(final int champion){
mytestInst.setInt(champion);
//runs "setInt" from the myapplicationtest class
this.finish();
//closes this current layout to run onActivityResult
}
在这段代码中,onActivityResult()似乎没有运行,因为“Champions.java”完成后,“ibChamp”的图片没有改变。如果有非常明显的内容,请指出,欢迎提出任何问题。
最佳答案
finish()
将终止 Activity。恕我直言,调用 finish()
然后进行布局更改是没有意义的(我假设 Activity 中的 View 已完成)。
关于java - 为什么 onActivityResult() 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22624138/