通过反射重新设置设置Dialog
通过反射重新设置Dialog:
public classDialogTest extends Activity {private static final int DIALOG_CLEAN = 1; // 清空文字private EditText edit; //要提交的内容@Overrideprotected void onCreate(Bundle icicle) {super.onCreate(icicle);setContentView(R.layout.bbs_topic_new_activity); //初始化控件 ... edit.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {clean();}}); }@Overrideprotected Dialog onCreateDialog(int id) {Builder builder = null;switch (id) {case DIALOG_CLEAN:builder = new AlertDialog.Builder(this).setTitle("提示").setMessage("确认清除全部内容?").setPositiveButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {edit.setText("");}}).setNeutralButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {disappearDialog(dialog);}});break;default:break;}return builder.create();}/** * 清除文字 */private void clean() {String content = edit.getText().toString();if (!content.equals("")) {showDialog(DIALOG_CLEAN);}}private void disappearDialog(DialogInterface dialog) {try {Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");field.setAccessible(true);field.set(dialog, true);} catch (Exception e) {e.printStackTrace();}}}?
?
? ?-