Mehrere ImageButtons(Bilder) über eine andere Activity ändern

  • 0 Antworten
  • Letztes Antwortdatum
A

adriax

Ambitioniertes Mitglied
0
Hallo Leute,

unzwar habe ich folgendes Problem,

ich habe eine "Map"-Activity mit ca. 12 ImageButtons, bei klick auf einem Button wird ein levelwert hinterlegt ( 1,2,3,...,12 ).
Nun soll bei der anderen Activity bei einer bestimmen Action ein Boolean auf true gesetzt werden. Wenn dieser Boolean == true ist soll sich das Bild vom gewählten Level (ImageButton) ändern...
nun komm ich hier irgentwie nicht weiter... :(

hier der Code hierzu:

MapActivity
Code:
package com.example.ssp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class MapActivity extends Activity implements OnClickListener {

	public static Integer lvl;
	public static ImageButton lvl1;
	public static ImageButton lvl2;
	public static ImageButton lvl3;
	public static ImageButton lvl4;
	public static ImageButton lvl5;
	public static ImageButton lvl6;
	public static ImageButton lvl7;
	public static ImageButton lvl8;
	public static ImageButton lvl9;
	public static ImageButton lvl10;
	public static ImageButton lvl11;
	public static ImageButton lvl12;
        private static Integer roundcounter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_map);
		
		
		lvl1 = (ImageButton) findViewById(R.id.imageButton1);
		lvl1.setOnClickListener(this);
		lvl2 = (ImageButton) findViewById(R.id.imageButton3);
		lvl2.setOnClickListener(this);
		lvl3 = (ImageButton) findViewById(R.id.imageButton2);
		lvl3.setOnClickListener(this);
		lvl4 = (ImageButton) findViewById(R.id.imageButton4);
		lvl4.setOnClickListener(this);
		lvl5 = (ImageButton) findViewById(R.id.imageButton5);
		lvl5.setOnClickListener(this);
		lvl6 = (ImageButton) findViewById(R.id.imageButton6);
		lvl6.setOnClickListener(this);
		lvl7 = (ImageButton) findViewById(R.id.imageButton7);
		lvl7.setOnClickListener(this);
		lvl8 = (ImageButton) findViewById(R.id.imageButton8);
		lvl8.setOnClickListener(this);
		lvl9 = (ImageButton) findViewById(R.id.imageButton9);
		lvl9.setOnClickListener(this);
		lvl10 = (ImageButton) findViewById(R.id.imageButton10);
		lvl10.setOnClickListener(this);
		lvl11 = (ImageButton) findViewById(R.id.imageButton11);
		lvl11.setOnClickListener(this);
		lvl12 = (ImageButton) findViewById(R.id.imageButton12);
		lvl12.setOnClickListener(this);
		
		if (lvl == null) {
			lvl = 1;
		}
		
		if(Game_started.levelcleared == true){
			Game_started.levelArray[lvl].setImageResource(R.drawable.levelclear);
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.map, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		if (v == lvl1) {
			lvl = 1;
			this.finish();
		}
		if (v == lvl2) {
			lvl = 2;
			this.finish();
		}
		if (v == lvl3) {
			lvl = 3;
			this.finish();
		}
		if (v == lvl4) {
			lvl = 4;
			this.finish();
		}
		if (v == lvl5) {
			lvl = 5;
			this.finish();
		}
		if (v == lvl6) {
			lvl = 6;
			this.finish();
		}
		if (v == lvl7) {
			lvl = 7;
			this.finish();
		}
		if (v == lvl8) {
			lvl = 8;
			this.finish();
		}
		if (v == lvl9) {
			lvl = 9;
			this.finish();
		}
		if (v == lvl10) {
			lvl = 10;
			this.finish();
		}
		if (v == lvl11) {
			lvl = 11;
			this.finish();
		}
		if (v == lvl12) {
			lvl = 12;
			this.finish();
		}
		Intent myIntent = new Intent(this, Choose.class);
		this.startActivity(myIntent);
	}

}

und hier die game activity:

Code:
package com.example.ssp;

import java.util.Random;


import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Game_started extends Activity implements OnClickListener {

	private Button button1;
	private ImageView spinning;
	private boolean running = true;
	static boolean levelcleared;
	public static ImageButton[] levelArray;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_game_started);

		ImageButton[] levelArray = {
				MapActivity.lvl1,
				MapActivity.lvl2,
				MapActivity.lvl3,
				MapActivity.lvl4,
				MapActivity.lvl5,
				MapActivity.lvl6,
				MapActivity.lvl7,
				MapActivity.lvl8,
				MapActivity.lvl9,
				MapActivity.lvl10,
				MapActivity.lvl11,
				MapActivity.lvl12
		};
						

	}
	public void onClick(View v) {
		if (v == button1) {

		      roundcounter++;
						
		      if(roundcounter == 3 ){
			    levelcleared = true;
			    Intent myIntent = new Intent(Game_started.this, MapActivity.class);
			    Game_started.this.startActivity(myIntent);

			    this.finish();
		      }
		}
		
	}

}

EDIT!!!:
Hat sich erledigt ;-) selbst ne Lösung gefunden.
 
Zuletzt bearbeitet:
Zurück
Oben Unten