Question

What I am aiming to do here is to change the picture of "ibChamp" from the default one to "ahri". Note that the names inside the ***s are the names of the 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
 }

In this code, the onActivityResult() does not seem to run, since after "Champions.java" is finished, "ibChamp"'s picture did not change. If there is something extremely obvious, please state it, and any questions are welcomed.

Was it helpful?

Solution 2

Change "int data" into "Intent data":

protected void onActivityResult(int requestCode, int resultCode, int data)

---->

protected void onActivityResult(int requestCode, int resultCode, Intent data)

OTHER TIPS

finish() will terminate the Activity. IMHO, it does not make sense to call finish() and then do layout changes (I ssume on the view in the Activity to be finished).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top