0

我想在另一个对话框中显示一个对话框,它工作正常,但是当我单击添加或编辑按钮时没有响应。我已经发布了下面的代码

    private Dialog myTextDialog(final String title) {
    final AlertDialog.Builder builder=new AlertDialog.Builder(this);

    builder.setView(getCurrentFocus());
    builder.setPositiveButton("ADD", new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            myAddCategory(title);
        }
    });
    builder.setNegativeButton("EDIT", new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            mAdapter = new MyExpandableListAdapter(MyGraphicalActivity.this, listOptionGroup, listOptionChild);
        }
    });
    return builder.create();
 }  

private Dialog myAddCategory(final String title) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);

    final View viewMessEdit = inflater.inflate(R.layout.add_category,(ViewGroup) findViewById(R.id.alertlayout));

    builder.setView(viewMessEdit);                  
   //viewMessEdit.setBackgroundResource(R.color.grayy);

    builder.setPositiveButton("ADD", new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            final EditText savedText = ((EditText) viewMessEdit.findViewById(R.id.inputbox));   
            newcategory=savedText.getText().toString();
            newcategory = checkCategory(newcategory);
            if(newcategory!="null" && newcategory.length()>0)
            {            
            Pattern pattern;                         
            pattern=Pattern.compile("[A-Z | a-z]*");
            Matcher matcher=pattern.matcher(newcategory);       
                if(!matcher.matches()) 
                {               
                    myTextDialog(title).show();
                    Toast.makeText(getBaseContext(),"Invalid Category name!",Toast.LENGTH_LONG).show();
                }
                else
                {               
                    Intent addcategorylist_intent=new Intent(MyGraphicalActivity.this,addcategorylist.class);
                    startActivity(addcategorylist_intent);
                    Toast.makeText(getBaseContext(), "ADDED", Toast.LENGTH_SHORT).show();
                }
            }
            else
            {
                myTextDialog(title).show();
                Toast.makeText(getBaseContext(),"You Can not give Blank & already specified Category!",Toast.LENGTH_LONG).show();            
            }
        }
    });
    builder.setNegativeButton("CANCEL",new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }             
    });

    return builder.create();
}
4

1 回答 1

2

更改以下代码

builder.setPositiveButton("ADD", new OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
        myAddCategory(title);
    }
});

builder.setPositiveButton("ADD", new OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
        myAddCategory(title).show();
    }
});
于 2012-05-17T05:42:30.193 回答