-2

当触发新的快速操作时,我试图调用新的警报对话框。但是我收到错误“无法在未调用 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{

                    }
                }
            });
4

1 回答 1

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(); 
   } 
于 2012-09-26T19:01:32.673 回答