How to get RadioButton to play music - java

So I have a class that will play some songs via the MediaPlayer. I have the following code that When a Radiobutton is selected should play a song, However this does not work, could anyone tell me why?
I do not get any errors, the music just does not play.
Code from the OnCheckedChange Method:
break;
case R.id.rFolk1: //setting up sub radiogroup buttons
if(fsong1.isPlaying() == false)
fsong1.start();
break;
case R.id.rFolk2: //setting up sub radiogroup buttons
if(fsong2.isPlaying() == false)
fsong2.start();
break;
Other code for the songs:
fsong1 = MediaPlayer.create(this, R.raw.folk1);
fsong2 = MediaPlayer.create(this, R.raw.folk2);
Fullcode:
public class Music extends Activity implements OnCheckedChangeListener, OnClickListener{
Button playpause;
RadioGroup selectionList, Folk, Rock, Pop, NewWave, Pipe;//define the radiogroup
RadioButton folk1, folk2, rock1, rock2, pop1, pop2, newwave1, newwave2, pipe1, pipe2; //define radiobuttons
MediaPlayer fsong1, fsong2, rsong1, rsong2, psong1, psong2, nwsong1, nwsong2, pisong1, pisong2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN );
setContentView(R.layout.music); //set layout
initialize(); //call this method
}
public void initialize(){
// set up the radiogroups
selectionList = (RadioGroup) findViewById(R.id.rgMusic);
Folk = (RadioGroup) findViewById(R.id.rgFolk);
Rock = (RadioGroup) findViewById(R.id.rgRock);
Pop = (RadioGroup) findViewById(R.id.rgPop);
Pipe = (RadioGroup) findViewById(R.id.rgPipe);
folk1 = (RadioButton) findViewById(R.id.rFolk1);
folk2 = (RadioButton) findViewById(R.id.rFolk2);
rock1 = (RadioButton) findViewById(R.id.rRock1);
rock2 = (RadioButton) findViewById(R.id.rRock2);
pipe1 = (RadioButton) findViewById(R.id.rPipe1);
pipe2 = (RadioButton) findViewById(R.id.rPipe2);
pop1 = (RadioButton) findViewById(R.id.rPop1);
pop2 = (RadioButton) findViewById(R.id.rPop2);
newwave1 = (RadioButton) findViewById(R.id.rNewWave1);
newwave2 = (RadioButton) findViewById(R.id.rNewWave2);
NewWave = (RadioGroup) findViewById(R.id.rgNewWave);
//settting up on check changed
selectionList.setOnCheckedChangeListener(this);
playpause = (Button) findViewById(R.id.bPlayPause);
playpause.setOnClickListener(this);
fsong1 = MediaPlayer.create(this, R.raw.folk1);
fsong2 = MediaPlayer.create(this, R.raw.folk2);
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
//case statement for onCheckChange to open a new class/layout
//
//This also hides radiogroups and shows others
switch(arg1){
case R.id.rFolk:
Folk.setVisibility(View.VISIBLE); //shows rg for folk
//hides all the rest of the radiogroups if visible
if(Pipe.getVisibility() == View.VISIBLE){
Pipe.setVisibility(View.GONE);
}
if(Rock.getVisibility() == View.VISIBLE){
Rock.setVisibility(View.GONE);
}
if(Pop.getVisibility() == View.VISIBLE){
Pop.setVisibility(View.GONE);
}
if(NewWave.getVisibility() == View.VISIBLE){
NewWave.setVisibility(View.GONE);
}
break;
case R.id.rPipe:
Pipe.setVisibility(View.VISIBLE);//shows rg for pipe
//hides all the rest of the radiogroups if visible
if(Folk.getVisibility() == View.VISIBLE){
Folk.setVisibility(View.GONE);
}
if(Rock.getVisibility() == View.VISIBLE){
Rock.setVisibility(View.GONE);
}
if(Pop.getVisibility() == View.VISIBLE){
Pop.setVisibility(View.GONE);
}
if(NewWave.getVisibility() == View.VISIBLE){
NewWave.setVisibility(View.GONE);
}
break;
case R.id.rRock:
Rock.setVisibility(View.VISIBLE);//shows rg for rock
//hides all the rest of the radiogroups if visible
if(Folk.getVisibility() == View.VISIBLE){
Folk.setVisibility(View.GONE);
}
if(Pipe.getVisibility() == View.VISIBLE){
Pipe.setVisibility(View.GONE);
}
if(Pop.getVisibility() == View.VISIBLE){
Pop.setVisibility(View.GONE);
}
if(NewWave.getVisibility() == View.VISIBLE){
NewWave.setVisibility(View.GONE);
}
break;
case R.id.rPop:
Pop.setVisibility(View.VISIBLE);//shows rg for pop
//hides all the rest of the radiogroups if visible
if(Folk.getVisibility() == View.VISIBLE){
Folk.setVisibility(View.GONE);
}
if(Pipe.getVisibility() == View.VISIBLE){
Pipe.setVisibility(View.GONE);
}
if(Rock.getVisibility() == View.VISIBLE){
Rock.setVisibility(View.GONE);
}
if(NewWave.getVisibility() == View.VISIBLE){
NewWave.setVisibility(View.GONE);
}
break;
case R.id.rNewWave:
NewWave.setVisibility(View.VISIBLE);//shows rg for newwave
//hides all the rest of the radiogroups if visible
if(Folk.getVisibility() == View.VISIBLE){
Folk.setVisibility(View.GONE);
}
if(Pipe.getVisibility() == View.VISIBLE){
Pipe.setVisibility(View.GONE);
}
if(Rock.getVisibility() == View.VISIBLE){
Rock.setVisibility(View.GONE);
}
if(Pop.getVisibility() == View.VISIBLE){
Pop.setVisibility(View.GONE);
}
break;
case R.id.rFolk1: //setting up sub radiogroup buttons
if(fsong1.isPlaying() == false){
fsong1.start();
}
break;
case R.id.rFolk2: //setting up sub radiogroup buttons
if(fsong2.isPlaying() == false){
fsong2.start();
}
}
}
#Override
public void onClick(View view) {
// setting the onclick listener for the buttons for play/pause stop
// check for already playing
if(fsong1.isPlaying()){
fsong1.pause();
// Changing button image to play button
playpause.setBackgroundResource(R.drawable.play_button);
}else{
// Resume song
fsong1.start();
// Changing button image to pause button
playpause.setBackgroundResource(R.drawable.pause_button);
}
}
}

I'd advise against creating so many MediaPlayers . They may very well be the cause of your troubles: When you instance too many of them they don't work well.
And you should take a look at the lifecycle of MediaPlayer as well.
In it you'll find one way to remove your multiple instances of MediaPlayers. You could, for instance change your playing to:
Boolean fsong1, fsong2, rsong1, rsong2, psong1, psong2, nwsong1, nwsong2, pisong1, pisong2;
Boolean isPlaying=false;
//lots of more code
case R.id.rFolk1: //setting up sub radiogroup buttons
if ((isPlaying) && !fsong1){
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
if (!fsong1){
//reset all other types of songs!
fsong1=true;
isPlaying = true;
mediaPlayer=MediaPlayer.create(this, R.raw.folk1);
mediaPlayer.start();
}
break;
Warning: I'm not giving you the whole change you'd have to apply!

Related

Hide ImageButton for first and last

Currently I build learning app for children. This app learn alphabet from "A" to "Z". If click the next button the alphabet will switch from A to B, B to C, and etc. But, I want if "A" the previous button (ImageButton) will be hide and if "Z" the next button will be hide.
public class ScrBelajarHuruf extends AppCompatActivity implements View.OnClickListener {
TextView txtHuruf;
ImageButton btnAudioHuruf, btnNextHuruf, btnPreviousHuruf;
MediaPlayer mediaPlayer;
int counterHurufList;
int counter = 0;
int counterAudioHurufList;
int[] stringHurufList = {
R.string.huruf_a,
R.string.huruf_b,
R.string.huruf_c,
R.string.huruf_d,
R.string.huruf_e,
R.string.huruf_f,
R.string.huruf_g,
R.string.huruf_h,
R.string.huruf_i,
R.string.huruf_j,
R.string.huruf_k,
R.string.huruf_l,
R.string.huruf_m,
R.string.huruf_n,
R.string.huruf_o,
R.string.huruf_p,
R.string.huruf_q,
R.string.huruf_r,
R.string.huruf_s,
R.string.huruf_t,
R.string.huruf_u,
R.string.huruf_v,
R.string.huruf_w,
R.string.huruf_x,
R.string.huruf_y,
R.string.huruf_z,
};
int[] rawAudioHurufList = {
R.raw.a,
R.raw.b,
R.raw.c,
R.raw.d,
R.raw.e,
R.raw.f,
R.raw.g,
R.raw.h,
R.raw.i,
R.raw.j,
R.raw.k,
R.raw.l,
R.raw.m,
R.raw.n,
R.raw.o,
R.raw.p,
R.raw.q,
R.raw.r,
R.raw.s,
R.raw.t,
R.raw.u,
R.raw.v,
R.raw.w,
R.raw.x,
R.raw.y,
R.raw.z,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scr_belajar_huruf);
txtHuruf = findViewById(R.id.txtHuruf);
btnAudioHuruf = findViewById(R.id.btnAudioHuruf);
btnNextHuruf = findViewById(R.id.btnNextHuruf);
btnPreviousHuruf = findViewById(R.id.btnPreviousHuruf);
btnAudioHuruf.setOnClickListener(this);
btnNextHuruf.setOnClickListener(this);
btnPreviousHuruf.setOnClickListener(this);
mediaPlayer = MediaPlayer.create(this, R.raw.a);
mediaPlayer.start();
if(counterHurufList == 0) {
btnPreviousHuruf.setVisibility(View.INVISIBLE);
}
}
public void onClick(View view) {
int id = view.getId();
if(id == R.id.btnNextHuruf && counterHurufList < stringHurufList.length - 1 && counterAudioHurufList < rawAudioHurufList.length - 1) {
mediaPlayer.stop();
counterHurufList++;
counterAudioHurufList++;
} else if (id == R.id.btnPreviousHuruf && counterHurufList > 0 && counterAudioHurufList > 0) {
mediaPlayer.stop();
counterHurufList--;
counterAudioHurufList--;
}
txtHuruf.setText(stringHurufList[counterHurufList]);
mediaPlayer = MediaPlayer.create(this, rawAudioHurufList[counterAudioHurufList]);
mediaPlayer.start();
}
}
I tried with
if(counterHurufList == 0) {
btnPreviousHuruf.setVisibility(View.INVISIBLE);
}
But give the previous button hide from "A" to "Z"
Haven't run this code so hopefully it works, but here are my thoughts from what you've shown:
You only perform the check to hide the button in onCreate, so it'll only do it once when the activity is created
You only hide the go back button
You only hide the button, and don't try to make it visible again
In your onCreate method, remove the check
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scr_belajar_huruf);
txtHuruf = findViewById(R.id.txtHuruf);
btnAudioHuruf = findViewById(R.id.btnAudioHuruf);
btnNextHuruf = findViewById(R.id.btnNextHuruf);
btnPreviousHuruf = findViewById(R.id.btnPreviousHuruf);
btnAudioHuruf.setOnClickListener(this);
btnNextHuruf.setOnClickListener(this);
btnPreviousHuruf.setOnClickListener(this);
mediaPlayer = MediaPlayer.create(this, R.raw.a);
mediaPlayer.start();
}
And in your onClick method, make sure you address all the points I mentioned above:
public void onClick(View view) {
int id = view.getId();
if(id == R.id.btnNextHuruf && counterHurufList < stringHurufList.length - 1 && counterAudioHurufList < rawAudioHurufList.length - 1) {
mediaPlayer.stop();
counterHurufList++;
counterAudioHurufList++;
} else if (id == R.id.btnPreviousHuruf && counterHurufList > 0 && counterAudioHurufList > 0) {
mediaPlayer.stop();
counterHurufList--;
counterAudioHurufList--;
}
txtHuruf.setText(stringHurufList[counterHurufList]);
mediaPlayer = MediaPlayer.create(this, rawAudioHurufList[counterAudioHurufList]);
mediaPlayer.start();
// New parts
btnPreviousHuruf.setVisibility(View.VISIBLE);
btnNextHuruf.setVisibility(View.VISIBLE);
if (counterHurufList == 0)
btnPreviousHuruf.setVisibility(View.INVISIBLE);
if (counterHurufList == 25)
btnNextHuruf.setVisibility(View.INVISIBLE);
}
Obviously modify however you like, but ensure that you meet the three criteria :)
switch (stringHurufList[counterHurufList]) {
case "A":
btnPreviousHuruf.setVisibility(View.INVISIBLE);
break;
case "Z":
btnNextHuruf.setVisibility(View.INVISIBLE);
break;
default:
btnPreviousHuruf.setVisibility(View.VISIBLE);
btnNextHuruf.setVisibility(View.VISIBLE);
}
But give the previous button hide from "A" to "Z"
Its because you forgot to return btn visibility to VISIBLE.
Declare an instance variable let's say int currentPosition = 0;. First time make previous button invisible prevBtn.setVisibility(View.INVISIBLE); Use this single position for both next and previous functionality. Like:
public void onClick(View view) {
int id = view.getId();
if(id == R.id.btnNextHuruf) {
currentPosition++;
prevBtn.setVisibility(View.VISIBLE);
if (currentPosition == 25){
nextBtn.setVisibility(View.INVISIBLE);
mediaPlayer.stop();
}
//counterHurufList++;
//counterAudioHurufList++;
} else if (id == R.id.btnPreviousHuruf) {
currentPosition--;
nextBtn.setVisibility(View.VISIBLE);
if (currentPosition == 0){
prevBtn.setVisibility(View.INVISIBLE);
mediaPlayer.stop();
}
}
txtHuruf.setText(stringHurufList[currentPosition]);
mediaPlayer = MediaPlayer.create(this, rawAudioHurufList[currentPosition]);
mediaPlayer.start();
}

How can I set the radiobutton selection with my method btnCalcularOnClick()? [duplicate]

This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 2 years ago.
I'm new to Java, and I'm trying to make a simple calculator for waist and hip ratio. However the ratio has different rules for each gender.
My trouble is to link the radio button gender selection with the method with if statement. How can I do this? I have tried this code below, but it didn't work.
public class CalcActivity1 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc1);
}
public void btnCalcularOnClick(View v) {
TextView resultado = (TextView) findViewById(R.id.lblResultado2);
EditText txtquadril = (EditText) findViewById(R.id.txtquadril);
EditText txtcintura = (EditText) findViewById(R.id.txtcintura);
RadioGroup group = (RadioGroup) findViewById(R.id.radio_group);
int quadril = Integer.parseInt(txtquadril.getText().toString());
int cintura = Integer.parseInt(txtcintura.getText().toString());
//CALC
double rcq = cintura / quadril;
int selectedId = group.getCheckedRadioButtonId();
// I tried here to link them
RadioButton RadioButton2 = (RadioButton) findViewById(selectedId);
String chave = RadioButton2.getText().toString().toLowerCase();
if (chave == "homem"){
if(rcq <= 0.95){
resultado.setText("Baixo");
}
else if(rcq > 0.96 & rcq <= 1){
resultado.setText("Moderado");
}
else {
resultado.setText("Alto");
}
}
if (chave == "mulher"){
if(rcq <= 0.80){
resultado.setText("Baixo");
}
else if(rcq > 0.81 & rcq <= 0.85){
resultado.setText("Moderado");
}
else {
resultado.setText("Alto");
}
}
}
}
Well your question is lil bit unclear that what you wanna do. If you have only one RadioButton, you do not need to use the RadioGroup rather simply use RadioButton but if you have more the one RadioButton you can place them inside RadioGroup.
Now, I am assuming you have more than one RadioButton inside RadioGroup.
Try to do this
if(group.getCheckedRadioButtonId() == R.id.RadioButton1) {
//RadioButton 1 Selected
String chave = ((RadioButton) findViewById(R.id.RadioButton1)).getText().toString()
if (chave.equalIgnoreCase("homem")){
//...
} else if (chave.equalIgnoreCase("melher")) {
//...
}
} else {
//RadioButton 2 Selected
}

Why is this playing sound on button click method not working

what I am trying to do is to call on one of three sounds on this button click. The sounds are in a preference screen. On the button click it is also supposed to display an animation. What is currently happening is I will click on the button and everything will work perfectly, but then I stop the animation and sound the second time I click the button. When I click the button again to start back up the animation and sound I cant hear the sound, but the animation still works. I honestly have no idea whats wrong. Here's my code...
public void buttonClick() {
imgView = (ImageView) findViewById(R.id.imageView);
button = (Button) findViewById(R.id.button);
blade = (ImageView)findViewById(R.id.imageView4);
final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
1stSound = MediaPlayer.create(this, R.raw.file.mp3);
2ndSound = MediaPlayer.create(this, R.raw.file.mp3);
3rdSOund = MediaPlayer.create(this, R.raw.file.mp3);
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean option1 = getPrefs.getBoolean("alternate", false);
boolean option2 = getPrefs.getBoolean("white", false);
boolean option3 = getPrefs.getBoolean("standard",false);
if (blade.getAnimation() == null) {
// no animation, start it
if (option1 == true){
1stSound.start();
blade.startAnimation(animRotate);
} else if (option2 == true){
3rdSound.start();
blade.startAnimation(animRotate);
} else if (option3 == true) {
2ndFan.start();
blade.startAnimation(animRotate);
}
} else {
//animation is showing, stop it
blade.clearAnimation();
3rdSound.stop();
2ndSound.stop();
1stSound.stop();
}
current_image_index++;
current_image_index = current_image_index % images.length;
imgView.setImageResource(images[current_image_index]);
imgView.invalidate();
}
}
);
}
Take a look at the MediaPlayer state diagram. After calling stop() you'll need to also call prepare() (or prepareAsync()) to be able to play it again.
In short, do this:
3rdSound.stop();
3rdSound.prepareAsync();
2ndSound.stop();
2ndSound.prepareAsync();
1stSound.stop();
1stSound.prepareAsync();

how to use if else statement for radiobuttons in android

I'm having two RadioGroups in one layout and each radiogroup has three radio buttons. so how can i use if else statement.
[two radiogroups in each group having three radiobuttons.when user clicked on one radiobutton then it will display correct answer.else wrong answer.][1]
Why do you want to use if else statement. You can do it in the easy way.
int radioButtonId = rbGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonId);
You can do like this to get the checked radiobutton from the radioGroup
RadioGroup g = (RadioGroup) findViewById(R.id.rBtnDigits);
switch (g.getCheckedRadioButtonId())
{
case R.id.rbtnButton1
//do something
break;
case R.id.rbtnButton2
//do something
break;
}
rg = (RadioGroup) findViewById(R.id.radioGroup1);
button = (RadioButton) findViewById(R.id.radio0);
rg.performClick();
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
#SuppressWarnings("unused")
int selected = rg.getCheckedRadioButtonId();
pos = rg.indexOfChild(findViewById(rg.getCheckedRadioButtonId()));
switch (pos) {
case 0:
Toast.makeText(getBaseContext(),
"You have Clicked RadioButton 1",
Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getBaseContext(),
"You have Clicked RadioButton 2",
Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getBaseContext(),
"You have Clicked RadioButton 3",
Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getBaseContext(),
"You have Clicked RadioButton 4",
Toast.LENGTH_SHORT).show();
break;
}
}
});

android java calling button from XML without getting NULL

I'm looking to call a few buttons but seem to be getting a NULL when trying to findbyviewid. When I activate this activity, it crashes.
//CREATE INSTANCE OF GLOBAL - QUESTIONS/ANSWERS
Global global = Global.getInstance();
//CURRENT QUESTION
static int QQ = 0;
//CORRECT ANSWER COUNT
static int correctAnswers = 0;
//CREATE VARIABLE FOR TEXTVIEW/QUESTION
TextView textQuestion = (TextView) findViewById(R.id.textQuestion);
//CREATE VARIABLES FOR BUTTONS/ANSWERS
Button buttonOne = (Button) findViewById(R.id.answerOne);
Button buttonTwo = (Button) findViewById(R.id.answerTwo);
Button buttonThree = (Button) findViewById(R.id.answerThree);
Button buttonFour = (Button) findViewById(R.id.answerFour);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_questions);
setButtons();
buttonOne.setOnClickListener(this);
buttonTwo.setOnClickListener(this);
buttonThree.setOnClickListener(this);
buttonFour.setOnClickListener(this);
}
public void setButtons()
{
//SET QUESTION STRING TO TEXTVIEW
textQuestion.setText(global.getQ(QQ));
//SET ANSWER STRINGS TO BUTTONS' TEXT
buttonOne.setText(global.getA(QQ, 0));
buttonTwo.setText(global.getA(QQ, 1));
buttonThree.setText(global.getA(QQ, 2));
buttonFour.setText(global.getA(QQ, 3));
}
#Override
public void onClick(View v)
{
switch(v.getId())
{
case R.id.answerOne:
checkAnswer(0, buttonOne);
break;
case R.id.answerTwo:
checkAnswer(1, buttonTwo);
break;
case R.id.answerThree:
checkAnswer(2, buttonThree);
break;
case R.id.answerFour:
checkAnswer(3, buttonFour);
break;
default:
break;
}
}
public void checkAnswer(int a, Button b){
//IF AN INCORRECT ANSWER WAS CHOSEN, MAKE THE BACKGROUND RED
if(!global.getS(QQ, a))
{
b.setBackgroundColor(Color.RED);
}
else
{
//INCREMENT THE CORRECT ANSWER COUNTER
correctAnswers++;
}
//SET BACKGROUND OF CORRECT BUTTON TO GREEN
if(global.getS(QQ, 0))
{
buttonOne.setBackgroundColor(Color.GREEN);
}
else if(global.getS(QQ, 1))
{
buttonTwo.setBackgroundColor(Color.GREEN);
}
else if(global.getS(QQ, 2))
{
buttonThree.setBackgroundColor(Color.GREEN);
}
else if(global.getS(QQ, 3))
{
buttonFour.setBackgroundColor(Color.GREEN);
}
else
{
//IF NO ANSWER IS CORRECT, SET ALL TO BLUE
buttonOne.setBackgroundColor(Color.BLUE);
buttonTwo.setBackgroundColor(Color.BLUE);
buttonThree.setBackgroundColor(Color.BLUE);
buttonFour.setBackgroundColor(Color.BLUE);
}
//MOVE TO NEXT QUESTION
}
I have 4 buttons in the XML file and want to be able to set the text to them, as well as run a listener for the set of buttons (answers to a question). When one of the buttons is clicked, it should determine if it's the correct answer by pulling the status (true/false) and highlighting it red if it's incorrect. It then highlights the correct answer green.
At least, some of this is in theory and I'm trying to test it out, but I can't start the activity without crashing.
I'm not 100% sure but I think you can't do the findViewById at the instance constructions. You need to those inside onCreate() (after you called setContentView)
Just how i said in comment, you should initialize it in OnCreate method, cause you set view layout for activity here. And before you do it, all findViewById returns null.
So, here your code:
Button buttonOne;
Button buttonTwo;
Button buttonThree;
Button buttonFour;
TextView textQuestion;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practice_questions);
buttonOne = (Button) findViewById(R.id.answerOne);
buttonTwo = (Button) findViewById(R.id.answerTwo);
buttonThree = (Button) findViewById(R.id.answerThree);
buttonFour = (Button) findViewById(R.id.answerFour);
textQuestion = (TextView) findViewById(R.id.textQuestion);
[...]
}

Categories

Resources