这是我的导入
package com.example.itbachelor.hangman;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Random;
以下是我为此课程做的下一步的声明
public class Noose extends Activity implements View.OnClickListener {
ImageView imageView2;
Button playButton2;
TextView textView6;
EditText letterText;
int count;
int imageArray[] = {R.drawable.noose, R.drawable.head, R.drawable.utorso, R.drawable.ltorso, R.drawable.arms, R.drawable.legs, R.drawable.dead};
String food1[] = {"B", "A", "S", "I", "L"};
String food2[] = {"O", "L", "I", "V", "E"};
String food3[] = {"C", "H", "I", "V", "E"};
String food4[] = {"G", "R", "A", "P", "E"};
String food5[] = {"L", "E", "M", "O", "N"};
Button buttons[]=new Button[5];
然后这是我的程序
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noose);
textView6 = (TextView) findViewById(R.id.textView6);
letterText = (EditText) findViewById(R.id.letterText);
playButton2 = (Button) findViewById(R.id.playButton2);
playButton2.setOnClickListener(this);
buttons[0] = (Button) findViewById(R.id.firstButton);
buttons[1] = (Button) findViewById(R.id.secondButton);
buttons[2] = (Button) findViewById(R.id.thirdButton);
buttons[3] = (Button) findViewById(R.id.fourthButton);
buttons[4] = (Button) findViewById(R.id.fifthButton);
Random rand = new Random();
int n = rand.nextInt(5);
imageView2.setImageResource(imageArray[0]);
这是一个刽子手应用,所以我想从5个单词开始比较
switch (n) {
case 0:
do {
View.OnClickListener add = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i <= food1.length - 1; i++) {
if (letterText.getText().toString().equals(food1[i])) {
System.out.print("Correct");
buttons[i].setText(food1[i]);
} else {
System.out.print("Incorrect!");
count++;
imageView2.setImageResource(imageArray[i]);
}
}
}
};
}
while (count < 6);
break;
请记住,我是这位
的初学者 case 1:
do {
View.OnClickListener add = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i <= food2.length - 1; i++) {
if (letterText.getText().toString().equals(food2[i])) {
System.out.print("Correct");
buttons[i].setText(food2[i]);
} else {
System.out.print("Incorrect!");
count++;
imageView2.setImageResource(imageArray[i]);
}
}
}
};
}
while (count < 6);
break;
case 2:
do {
View.OnClickListener add = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i <= food3.length - 1; i++) {
if (letterText.getText().toString().equals(food3[i])) {
System.out.print("Correct");
buttons[i].setText(food3[i]);
} else {
System.out.print("Incorrect!");
count++;
imageView2.setImageResource(imageArray[i]);
}
}
}
};
}
while (count < 6);
break;
case 3:
do {
View.OnClickListener add = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i <= food4.length - 1; i++) {
if (letterText.getText().toString().equals(food4[i])) {
System.out.print("Correct");
buttons[i].setText(food4[i]);
} else {
System.out.print("Incorrect!");
count++;
imageView2.setImageResource(imageArray[i]);
}
}
}
};
}
while (count < 6);
break;
case 4:
do {
View.OnClickListener add = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i <= food5.length - 1; i++) {
if (letterText.getText().toString().equals(food5[i])) {
System.out.print("Correct");
buttons[i].setText(food5[i]);
} else {
System.out.print("Incorrect!");
count++;
imageView2.setImageResource(imageArray[i]);
}
}
}
};
}
while (count < 6);
break;
}
}
我的程序至少会切换页面,但现在它不会。不确定我哪里出错了