Skip to content

Instantly share code, notes, and snippets.

@Bapho
Last active December 29, 2015 06:49
Show Gist options
  • Save Bapho/7631926 to your computer and use it in GitHub Desktop.
Save Bapho/7631926 to your computer and use it in GitHub Desktop.
This is the on-click button listener for the start activity. -three-day project
package com.baphoware.prjhelloween.listener;
import com.baphoware.prjhelloween.R;
import com.baphoware.prjhelloween.activities.GameActivity;
import com.baphoware.prjhelloween.activities.HelloWeenActivity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
public class HelloWeenActivityOnClickListener implements OnClickListener
{
// Intent deklarieren
private Intent intentGame = null;
public HelloWeenActivityOnClickListener()
{
// standard constructor
}
@Override
public void onClick( View v )
{
// Fallprüfung
switch( v.getId() )
{
case R.id.cmdStart:
// Intent initialisieren
intentGame = new Intent( v.getContext(), GameActivity.class );
// Activity starten, wenn der Intent nicht "null" ist
if( intentGame != null )
{
v.getContext().startActivity( intentGame );
}
break;
// beenden
case R.id.cmdExit:
// CAST view.-context to MainActivity EXPLIZITER CAST
HelloWeenActivity gameActivity = (HelloWeenActivity) v.getContext();
gameActivity.finish();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment