-4
我利用數組列表imageView shuffle,如何將輸入列表中的數組索引值轉換爲if條件?示例代碼如下,但如果條件不想走路,解決方案是什麼?如何在Android編程中使用數組索引列表?
這是代碼:(。soal.equals(list.get(0))& & text.getText()的toString()等於( 「1」))如果
public class tebakgambar extends Activity implements OnClickListener {
private Button ok;
private ImageView soal;
private EditText text;
ArrayList<Integer> list = new ArrayList<Integer>() {{
add(R.drawable.siji);
add(R.drawable.loro);
add(R.drawable.telu);
add(R.drawable.papat);
add(R.drawable.limo);
add(R.drawable.enem);
add(R.drawable.pitu);
add(R.drawable.wolu);
add(R.drawable.songo);
add(R.drawable.nol);
}};
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal);
soal = (ImageView) findViewById(R.id.imageView);
text = (EditText) findViewById(R.id.editText);
ok = (Button) findViewById(R.id.button);
ok.setOnClickListener(this);
}
public void onClick(View v) {
acak();
jawaban();
}
private void acak(){
Collections.shuffle(list);
soal.setImageResource(list.get(0));
soal.setTag(list.get(0));
}
private void jawaban() {
if (soal.equals(list.get(0)) && text.getText().toString().equals("one")) {
text.setText("");
// get your custom_toast.xml ayout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.benar);
// set a message
// TextView text = (TextView) layout.findViewById(R.id.text);
//text.setText("Benar");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
} else {
text.setText("");
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.salah);
// set a message
// TextView text = (TextView) layout.findViewById(R.id.text);
//text.setText("Benar");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
問題解決了嗎?或者你需要更多幫助嗎? –