我试图在新的快速操作触发时调用新警报对话框。但是我得到错误“无法在没有调用Looper.prepare()的线程内创建处理程序”..你能告诉我如何解决这个问题吗?
quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
public void onItemClick(QuickAction source, int pos, int actionId) {
ActionItem actionItem = quickAction.getActionItem(pos);
//here we can filter which action item was clicked with pos or actionId parameter
if (actionId == ID_PASSC) {
} else if (actionId == ID_PASS) {
final Thread t = new Thread() {
@Override
public void run() {
try {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.password_dialog, (ViewGroup) findViewById(R.id.root));
final EditText password1 = (EditText) layout.findViewById(R.id.EditText_Pwd1);
final EditText password2 = (EditText) layout.findViewById(R.id.EditText_Pwd2);
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Change password");
builder.setView(layout);
builder.show();
} finally {
}
}
};
t.start();
} else if (actionId == ID_HELP){
}else{
}
}
});
答案 0 :(得分:0)
你总是需要在UI线程上进行UI操作。我不知道你为什么要创建一个新线程来创建一个对话框。删除创建新线程并同步显示对话框,如下所示。
} else if (actionId == ID_PASS) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = inflater.inflate(R.layout.password_dialog, (ViewGroup) findViewById(R.id.root));
final EditText password1 = (EditText) layout.findViewById(R.id.EditText_Pwd1);
final EditText password2 = (EditText) layout.findViewById(R.id.EditText_Pwd2);
AlertDialog.Builder builder = new AlertDialog.Builder([ActivityName].this);
builder.setTitle("Change password");
builder.setView(layout);
builder.show();
}