我的目的是将“ ibChamp”的图片从默认图片更改为“ ahri”。请注意,***中的名称是活动的名称。
***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()
将终止活动。恕我直言,先调用finish()
然后更改布局是没有意义的(我想在Activity中的视图上完成)。