0
我正在打牌,我想顯示一個對話框提示用戶選擇一套西裝。我製作對話框並設置佈局。只要我嘗試使用setadapter填充微調框,我的應用就會出現白屏,並從頭開始重新加載。這是下面的代碼。Android spinner爲什麼我不能像普通人一樣顯示下拉菜單?
private void showChooseSuitDialog(){
final Dialog chooseSuitDialog = new Dialog(myContext);
chooseSuitDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
chooseSuitDialog.setContentView(R.layout.choose_suit_dialog);
final Spinner suitSpinner = (Spinner)findViewById(R.id.suitSpinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(myContext, R.array.suits, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
suitSpinner.setAdapter(adapter); // **** This is where it blows up ****
// Button okButton = (Button) chooseSuitDialog.findViewById(R.id.okButton);
// okButton.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// validSuit = (suitSpinner.getSelectedItemPosition()+1) * 100;
// String suitText = "";
// if(validSuit == 100){
// suitText = "Diamonds";
// }else if(validSuit == 200){
// suitText = "Clubs";
// }else if(validSuit == 300) {
// suitText = "Hearts";
// }else {
// suitText = "Spades";
// }
// chooseSuitDialog.dismiss();
// Toast.makeText(myContext, "You chose " + suitText, Toast.LENGTH_SHORT).show();
// }
// });
請分享您的choose_suit_dialog.xml – 0X0nosugar
以及'suits'數組的定義。 – rekire