不用找了,这才是正解。你的需求其实是,需要一个阻塞式对话框,安卓本身所有弹窗都是非阻塞的。
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.EditText;
/**
* 动态获取用户输入后在继续后面的流程
* 这是一个模态阻塞对话框(阻塞主线程,结果不用回调来处理)
*/
public class BlockingInputDialog {
String mInputString = "";
Activity mContext;
String mTitle;
EditText mEditText;
Handler mHandler;
public BlockingInputDialog(Activity context, String title){
mContext = context;
mTitle = title;
}
public String showDialog(){
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
//super.handleMessage(msg);
throw new RuntimeException();
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(mTitle);
builder.setCancelable(false);
mEditText = new EditText(mContext);
builder.setView(mEditText);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mInputString = mEditText.getText().toString();
Message message = mHandler.obtainMessage();
mHandler.sendMessage(message);
}
});
builder.setNegativeButton("取消", null);
builder.create().show();
try {
Looper.getMainLooper().loop();
}
catch(RuntimeException e2)
{
}
return mInputString;
}
}
你可以使用hanlder发送消息,等点击确定后,发送消息在弹出一个消息框
弹出输入框?输入内容后,确定,再弹出一个提示框显示内容?