public class MainActivity extends ActionBarActivity implements View.OnClickListener { ImageView bild; Button bild_laden; int i = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Beider Mediaplayer deklarieren und mit Lied initialisieren; MediaPlayer titelLied1 = MediaPlayer.create(this, R.raw.theme_1); MediaPlayer titelLied2 = MediaPlayer.create(this, R.raw.theme_2); titelLied1.start(); titelLied2.setLooping(true); //Naechster Lied starten; titelLied1.setNextMediaPlayer(titelLied2); bild = (ImageView) findViewById((R.id.imageView)); bild_laden = (Button)findViewById(R.id.bild_laden); bild_laden.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onClick(View v) { // Toast.makeText(this, getResources().getDisplayMetrics().toString(), LENGTH_LONG).show(); if (i == 0) { try { bild.setImageResource(R.drawable.child); bild_laden.setText("nächstes Bild Laden"); i++; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } if ( i == 1) { try { bild.setImageResource(R.drawable.n0); i++; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } if (i == 2) { try { bild.setImageResource(R.drawable.n1); i++; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } if (i == 3) { try { bild.setImageResource(R.drawable.n2); i++; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } if (i == 4) { try { bild.setImageResource(R.drawable.n3); i++; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } if (i == 5) { try { bild.setImageResource(R.drawable.n4); i = 0; return; } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } } } }