每个人都听说过徽标测验!我尝试开发像徽标测验这样的游戏,这是您必须在其中输入徽标名称的活动!图像和名称由 intent 接收。图像标签包含名称。
public class Vie extends Activity implements OnClickListener {
ImageView img;
EditText et;
Button btn;
TextView txt;
MediaPlayer win_sound, wrong_sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.vie);
img = (ImageView) findViewById(R.id.img);
et = (EditText) findViewById(R.id.et);
btn = (Button) findViewById(R.id.btnCheck);
txt = (TextView) findViewById(R.id.txt);
win_sound = MediaPlayer.create(Vie.this, R.raw.win);
wrong_sound= MediaPlayer.create(Vie.this, R.raw.wrong);
setImageAndTagByIntent(img);
btn.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
boolean mb = check(et, btn, img);
if (mb = true) {
// Sunet toast thread
txt.setText(title(img));
win_sound.start();
Thread t = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
try {
sleep(win_sound.getDuration());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
finish();
}
}
};
t.start();
}
if (mb = false) {
// sunet toast thread
wrong_sound.start();
Toast t = new Toast(Vie.this);
t.setText("Wrong answer! Please check if you have spelled corectly the name of the team!");
t.show();
}
}
private CharSequence title(ImageView img2) {
// TODO Auto-generated method stub
String s = (String) img2.getTag();
return s;
}
private void setImageAndTagByIntent(ImageView img2) {
// TODO Auto-generated method stub
// Trece si tagul!
Intent i = getIntent();
Bitmap back = i.getParcelableExtra("back");
Drawable b = new BitmapDrawable(getResources(), back);
img2.setImageDrawable(b);
String tag = i.getStringExtra("tag");
Object tag2 = (Object) tag;
img2.setTag(tag2);
}
private boolean check(EditText et2, Button btn2, ImageView img2) {
// TODO Auto-generated method stub
String s = et2.getText().toString();
s = WordUtils.capitalize(s);
String s1 = (String) img2.getTag();
boolean b = false;
if (hasBlank(s1) == true && s.contentEquals(firstWord(s1))) {
b = true;
}
if (hasBlank(s1) == true && s.contentEquals(lastWord(s1))) {
b = true;
}
if (s.contentEquals(s1) && hasBlank(s1) == false) {
b = true;
}
return b;
}
private String lastWord(String s1) {
// TODO Auto-generated method stub
String arr[] = s1.split("//s");
return arr[1];
}
private String firstWord(String s1) {
// TODO Auto-generated method stub
String arr[] = s1.split("//s");
return arr[0];
}
private boolean hasBlank(String string) {
// TODO Auto-generated method stub
if (string.contains(" ")) {
return true;
}
return false;
}
}
但是当我在编辑文本中写任何东西时,它看起来是正确的!请帮我!我认为这是布尔方法的问题!