0
顯示對話框我有,我想用它來顯示一個對話框消息的簡單類:Android的 - 從靜態類
public class Utils {
static void ShowMessage(Context c, String DialogTitle, String MessageToDisplay, int LayoutResourceID, int ImageResourceID){
//Create new dialog.
Dialog dialog = new Dialog(c);
//Set the view to an existing xml layout.
dialog.setContentView(LayoutResourceID);
dialog.setTitle(DialogTitle);
//Set textbox text and icon for dialog.
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(MessageToDisplay);
ImageView image = (ImageView)dialog.findViewById(R.id.image);
image.setImageResource(ImageResourceID);
//Show the dialog window.
dialog.show();
}
}
我想從我的活動調用它,的一個OnClickListener事件中按鈕,像這樣:
private OnClickListener btnSubmitIssueClick = new OnClickListener(){
public void onClick(View v){
//Check for valid Summary & Description.
if(mSummaryEditText.getText().toString().trim().length() == 0){
Utils.ShowMessage(getBaseContext(), "Submit Issue Error", getBaseContext().getString(R.string.ERROR_SummaryRequired),
R.layout.modal_dialog, R.drawable.warning);
return;
}else if(mDescriptionEditText.getText().toString().trim().length() == 0){
Utils.ShowMessage(getBaseContext(), "Submit Issue Error", getBaseContext().getString(R.string.ERROR_DescriptionRequired),
R.layout.modal_dialog, R.drawable.warning);
return;
}
}
};
但是當我運行它,我得到這個錯誤:
03-07 16:56:00.290: W/WindowManager(169): Attempted to add window with non-application token WindowToken{4162e780 token=null}. Aborting.
任何想法,我是什麼做錯了?
感謝您的鏈接......我總是很難區分「getContext」方法的類型。 – Robert 2012-03-08 02:33:48