我正在用AlertDialog.Builder創建一個自定義AlertDialog。但是,我無法讓我的微調工具在AlertDialog中工作。每當我點擊微調,我得到的是說如何添加微調器到AlertDialog.Builer?
android.view.WindowManager BadTokenException: Unable to add window--token null
is not for an application
最初的錯誤,我想這是因爲我的自定義適配器,但是這並不是錯誤的原因。我不明白爲什麼會發生這種情況。我已經用這種方式編碼了我的紡紗商多年,並且從來沒有遇到過這個問題。這是我的代碼。提前致謝。
public void openCustomDialog(){
AlertDialog.Builder customDialog= new AlertDialog.Builder(Portfolio.this);
customDialog.setTitle("Create Portfolio");
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.createdialog,null);
EditText enterportfolioname = (EditText)view.findViewById(R.id.enterportfolioname);
Spinner denominationselection = (Spinner)view.findViewById(R.id.denomination);
ArrayAdapter<String> adaptercreatetype;
createdenominationsarray = getResources().getStringArray(R.array.createdenominations);
adaptercreatetype = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,createdenominationsarray){
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View v = null;
// If this is the initial dummy entry, make it hidden
if (position == 0) {
TextView tv = new TextView(getContext());
tv.setHeight(0);
tv.setVisibility(View.GONE);
v = tv;
}
else {
// Pass convertView as null to prevent reuse of special case views
v = super.getDropDownView(position, null, parent);
}
// Hide scroll bar because it appears sometimes unnecessarily, this does not prevent scrolling
parent.setVerticalScrollBarEnabled(false);
return v;
}
};
adaptercreatetype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
denominationselection.setAdapter(adaptercreatetype);
customDialog.setPositiveButton("Save", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog,int which) {
// TODO Auto-generated method stub
}});
customDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog,int which) {
// TODO Auto-generated method stub
}});
customDialog.setView(view);
customDialog.show();
}