protected Dialog onCreateDialog(int id) {
switch(id)
{
case NEWMESSAGEDIALOG:
LayoutInflater lf=LayoutInflater.from(this);
final View alertView=lf.inflate(R.layout.newmessagedialog, null);
final ImageButton newMessageIB=(ImageButton) alertView.findViewById(R.id.newmessageSearch);
final EditText newMessageNumber=(EditText) alertView.findViewById(R.id.newmessageNumber);
final EditText newMessageNeiRong=(EditText) alertView.findViewById(R.id.newmessageEditText);
final AlertDialog.Builder newMessageDialog=new AlertDialog.Builder(this);
newMessageDialog.setView(alertView);
newMessageDialog.setTitle(this.getResources().getString(R.string.newMessage_Title));
newMessageDialog.setPositiveButton(this.getResources().getString(R.string.sentbutton), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
if(newMessageNumber.getText().toString().equals(""))
{
Toast.makeText(InBoxActivity.this, R.string.numberIsNull, Toast.LENGTH_SHORT).show();
return;
}
else if(newMessageNeiRong.getText().toString().equals(""))
{
Toast.makeText(InBoxActivity.this, R.string.messageIsNull, Toast.LENGTH_SHORT).show();
return;
}
// MyAsyncTask task=new MyAsyncTask();
}});
return newMessageDialog.create();
}
return super.onCreateDialog(id);
}
之前用了this.findViewById应该改为final ImageButton newMessageIB=(ImageButton) alertView.findViewById(R.id.newmessageSearch);