Java/xml button not working?



I'm following a tutorial on youtube, and this part should make a blue rectangle appear on the top half of the screen.


When I click the button to open that screen a little black box with 'thebasics' (the name of the app) appears and wont disappear until I click on the screen.


I've set up buttons which open new screens fine before, so I'm stuck as to why this isnt working.


Here is where the buttons are set up:



public class menu extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//adding button sound
final MediaPlayer buttonSound = MediaPlayer.create(menu.this, R.raw.button_click);


//setting up button references
Button tut1 = (Button) findViewById(R.id.tutorial1);
Button tut2 = (Button) findViewById(R.id.tutorial2);
Button tut3 = (Button) findViewById(R.id.tutorial3);
Button tut4 = (Button) findViewById(R.id.tutorial4);

tut1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonSound.start();
startActivity(new Intent("com.example.thebasics.TUTORIALONE"));
}
});


tut2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonSound.start();
startActivity(new Intent("com.example.thebasics.TUTORIALTWO"));
}
});


tut3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonSound.start();
startActivity(new Intent("com.example.thebasics.TUTORIALTHREE"));
}
});

tut4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonSound.start();
startActivity(new Intent("com.example.thebasics.TUTORIALFOUR"));
}
});


}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}

public boolean onCreateOptionsMenu(Menu menu){

super.onCreateOptionsMenu(menu);
MenuInflater awesome = getMenuInflater();
awesome.inflate(R.menu.main_menu, menu);
return true;
}


}


Here is the class for tutorial four (the one which isn't working):



public class TutorialFour extends Activity {

DrawingTheBall v;

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
v= new DrawingTheBall(this);
setContentView(v);


}


}


Here the DrawingTheBall class which it uses in case this is the issue:



public class DrawingTheBall extends View {

public DrawingTheBall(Context context){
super(context);
// TODO Auto-generated constructor stub

}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

Rect ourRect = new Rect();
ourRect.set(0,0,canvas.getWidth(), canvas.getHeight()/2);
Paint blue = new Paint();
blue.setColor(Color.BLUE);
blue.setStyle(Paint.Style.FILL);


canvas.drawRect(ourRect, blue);
}


}


And finally here is the excerpt from the manifest where I set up the intent:



<activity
android:name=".TutorialFour"
android:theme ="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.example.thebasics.TUTORIALFOUR" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


Any Help would be greatly appreciated.


No comments:

Post a Comment