首页 > 代码库 > AlertDialog错误

AlertDialog错误

Unable to add window token null is not for an application 
  AlertDialog.Builder localBuilder = new AlertDialog.Builder(Service_Activity.this);
// 这里使用getApplicationContext() 报错 必须使用当前activity。

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------

textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
           
                AlertDialog.Builder localBuilder = new AlertDialog.Builder(Service_Activity.this);
                 localBuilder.setTitle("编辑地址").setIcon(R.mipmap.bianji);
//
final LinearLayout layout_alert= (LinearLayout) getLayoutInflater().inflate(R.layout.layout_alertservicejiekou, null); localBuilder.setView(layout_alert); localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
              // 这里使用(LinearLayout) getLayoutInflater().inflate(R.layout.layout_alertservicejiekou, null).findViewByid(R.id.edit1)
             // .getText().toString()是得不到数据的
EditText edit1
= (EditText) layout_alert.findViewById(R.id.edit1); System.out.println("***out"+edit1.getText().toString()); textView1.setText(edit1.getText().toString().trim()); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { } }).create().show();

 

AlertDialog错误