無効化ボタンに問題があります。
私のコード
public class try1 extends Activity {
private String[] myString1;
private static final Random rgenerator = new Random();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
myString1 = res.getStringArray(R.array.primary);
final Button btn1;
btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String q = myString1[rgenerator.nextInt(myString1.length)];
((Button) v).setText(q);
if( findViewById(R.id.button5).getVisibility() == View.VISIBLE)
{
Toast.makeText(getBaseContext(), "Press Next to Go", Toast.LENGTH_SHORT).show();
}
}
});
final Button btn2;
btn2 = (Button) findViewById(R.id.button2);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String q = myString1[rgenerator.nextInt(myString1.length)];
((Button) v).setText(q);
if( findViewById(R.id.button5).getVisibility() == View.VISIBLE)
{
Toast.makeText(getBaseContext(), "Press Next to Go", Toast.LENGTH_SHORT).show();
}
}
});
final Button btn3;
btn3 = (Button) findViewById(R.id.button3);
btn3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String q = myString1[rgenerator.nextInt(myString1.length)];
((Button) v).setText(q);
if( findViewById(R.id.button5).getVisibility() == View.VISIBLE)
{
Toast.makeText(getBaseContext(), "Press Next to Go", Toast.LENGTH_SHORT).show();
}
}
});
final Button check;
check = (Button) findViewById(R.id.button4);
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String q = myString1[rgenerator.nextInt(myString1.length)];
((Button) v).setText(q);
if (btn1.getText().equals(" ")||(btn2.getText().equals(" ")||(btn3.getText().equals(" "))))
{
Toast.makeText(getBaseContext(), "choose answer", Toast.LENGTH_SHORT).show();
}
else if (btn1.getText().toString().equals(myString1[1])||(btn1.getText().toString().equals(myString1[2])||
(btn2.getText().toString().equals(myString1[0])||(btn2.getText().toString().equals(myString1[2])||
(btn3.getText().toString().equals(myString1[0])||(btn3.getText().toString().equals(myString1[1])
))))))
{
Toast.makeText(getBaseContext(), "wrong answer", Toast.LENGTH_SHORT).show();
}
else if (btn1.getText() == btn2.getText()|| (btn1.getText() == btn3.getText()||
(btn2.getText() == btn3.getText())))
{
Toast.makeText(getBaseContext(), "something same", Toast.LENGTH_SHORT).show();
}
else if(btn1.getText().toString().equals(myString1[0]) &&
(btn2.getText().toString().equals(myString1[1]) &&
(btn3.getText().toString().equals(myString1[2]) )))
{
findViewById(R.id.imageView1).setVisibility(View.VISIBLE);
}
}
});
Button next;
next = (Button) findViewById(R.id.button5);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent("com.learn.lone"));
}
});
}
}
クリック時button1, button2, button3
にランダムなテキストが表示される場合、
チェックボタンがあります。このボタンは、上のボタンの答えが正しいか間違っているかをチェックするのに役立ちます。正解が表示される場合ImageView
ImageView
ボタン 1、ボタン 2、ボタン 3 がクリックできません。[次へ]をクリックして続行することしかできません。
何を追加すればよいですか?