I have an activity where the user can select their character. I have three image buttons on the screen and when the user clicks the character they want, I want the game to load another activity that will then just show an image of the character they selected in the previous screen. Basically this is just the forerunner for what I am going to do later. I found some examples on this website for how to accomplish this but I haven't quite gotten it all ironed out.
This is what I have in my character selection activity:
Button archerButton = (Button) findViewById(R.id.Button_Archer);
archerButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(SelectCharacterActivity.this, LevelOneActivity.class);
intent.putExtra("@drawable/archer", pathToImage);
startActivity(intent);
finish();
}
});
The pathToImage line is throwing an error. What exactly am I supposed to put here?
The LevelOne activity which is supposed to just display the image chosen has this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.level_one);
String path = getIntent().getStringExtra("imagePath");
Drawable image = Drawable.createFromPath(path);
Character_Chosen.setImageDrawable(image);
}
I'm a bit confused on this section as well. The Character_Chosen entry is the name of the imageview which should house the selected image.
I'm also confused on this line of code:
String path = getIntent().getStringExtra("imagePath");
Does this mean I have to manually enter the image path every time? What if they choose a different image?
Does anyone have a link to an actual working example? Pseudo code doesn't really help me very much when I'm a novice and don't know what needs to stay and what needs to go.