I'm developing a simple android game divided into levels. I want a check icon (ImageView) to appear next to a level button (on level select menu) when that level is completed. A level is completed after pressing a button, as follows (InsideLevelActivity):
final EditText level1editText=(EditText)findViewById(R.id.level1editText);
Button level1completeButton=(Button)findViewById(R.id.level1completeButton);
level1completeButton.setOnClickListener(new View.OnClickListener()
public void onClick(View v)
{
final String edittext=level1editText.getText().toString();
if(edittext.trim().equals("Complete level"))
{
{
Intent visible1 = new Intent();
visible1.putExtra("iconvisible",0);
startActivity(visible1);
{
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.activity_level1completed,
(ViewGroup) findViewById(R.id.img11_toast));
Toast toast = new Toast(Level1Activity.this);
toast.setView(view);
toast.show();
{ onBackPressed(); {
return;
}
}
}
else
{
Toast.makeText(Level1Activity.this,
"Type Complete level.", Toast.LENGTH_LONG).show();
}
And then returns to level select menu activity. I'm trying to retrieve data this way (LevelMenuActivity):
ImageView logocheckicon1=(ImageView)findViewById(R.id.logocheckicon1);
logocheckicon1.setVisibility(View.GONE);
Intent visible1 = getIntent();
int state = Integer.parseInt(visible1.getExtras().get("iconvisible").toString());
complete1.setVisibility(iconvisible);
I've tried many approaches for the last couple of days, including this one (how to pass data between two activities). I've even tried to make the check icon (ImageView) invisible, and making it visible again this way.
Also, the same check icon will appear next to every completed level. Is it possible to acomplish this with only one ImageView (without creating 10 different IDs of the same drawable)?
Thank you in advance.
EDIT: I apologize if i wasn't clear enough. I tought there was some way to change the visibility of an image located, for instance, on MainActivity with an intent inside the button on another activity. Thank you for your answers.
EDIT2: Added the code of another unsuccessful try.