Hey Guys/gals,
I was doing some tutorials, when I finished one i ran in to a problem.
The code down here shows an error in Eclipse:
btnDialog.setOnClickListener(new OnClickListener() {
I got 3 of these listeners.
The auto correct tools only suggests to change setOnClickListener to any other listener. I've searched the web a bit but didn't find an awnser.
Bellow if the whole code:
package app.weaselmummy.androidtest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class testApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.dialog_title);
dialog.setMessage(R.string.dialog_text);
dialog.setPositiveButton(R.string.dialog_ok, null);
dialog.setNegativeButton(R.string.dialog_cancel, null);
Button btnDialog = (Button) findViewById(R.id.Button01);
btnDialog.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.show();
}
});
Button btnSound = (Button) findViewById(R.id.Button02);
btnSound.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MediaPlayer player = new MediaPlayer();
try {
player.setDataSource(getString(R.string.sound_file));
player.prepare();
player.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
Button btnRelative = (Button) findViewById(R.id.Button03);
btnRelative.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(testApp.this, Relative.class);
startActivity(i);
finish();
}
});
}
}
Would appreciate any help!
I was doing some tutorials, when I finished one i ran in to a problem.
The code down here shows an error in Eclipse:
btnDialog.setOnClickListener(new OnClickListener() {
I got 3 of these listeners.
The auto correct tools only suggests to change setOnClickListener to any other listener. I've searched the web a bit but didn't find an awnser.
Bellow if the whole code:
package app.weaselmummy.androidtest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class testApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.dialog_title);
dialog.setMessage(R.string.dialog_text);
dialog.setPositiveButton(R.string.dialog_ok, null);
dialog.setNegativeButton(R.string.dialog_cancel, null);
Button btnDialog = (Button) findViewById(R.id.Button01);
btnDialog.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.show();
}
});
Button btnSound = (Button) findViewById(R.id.Button02);
btnSound.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MediaPlayer player = new MediaPlayer();
try {
player.setDataSource(getString(R.string.sound_file));
player.prepare();
player.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
Button btnRelative = (Button) findViewById(R.id.Button03);
btnRelative.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(testApp.this, Relative.class);
startActivity(i);
finish();
}
});
}
}
Would appreciate any help!