开发者

how to change text in AlertDialog before onClick event

开发者 https://www.devze.com 2023-02-08 08:11 出处:网络
I\'m having trouble with settting some text to EditText every time a dialog is loaded. The problem is whenever the dialog window appears there should be some specific text in the editText that can be

I'm having trouble with settting some text to EditText every time a dialog is loaded.

The problem is whenever the dialog window appears there should be some specific text in the editText that can be edited. It can't be made static (defined in XML), so where should I put the code like wrapper.setText("some phone number etc");?

Here is the code:

private void edit(final long id) {
    if (id>0)
    {
        LayoutInflater inflator = LayoutInflater.from(this);
        View dialogView = inflator.inflate(R.layout.editonly, null);
        final editDialogContentGetter wrapper = new editDialogContentGetter(dialogView);
        new AlertDialog.Builder(this).setTitle(R.string.edit).
        setView(dialogView).setPositiveButton(R.string.edit,new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                basicallyEdit(wrapper);
            }}).setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int which) {
 开发者_StackOverflow社区                   Toast.makeText(AllPhones2.this,R.string.nochange,Toast.LENGTH_SHORT).show();
                }}).show();
    }
}
protected void basicallyEdit(editDialogContentGetter wrapper) {
        // some code here to process information  recieved by the dialog
}
class editDialogContentGetter
{
    //class for dialog
    EditText editphoneBox = null;
    View base2 = null;
    public  editDialogContentGetter(View base2) {
        // TODO Auto-generated constructor stub
        this.base2 = base2;
    }
    public EditText getEditBoxField()
    {
        if(editphoneBox==null)
    {
        editphoneBox =(EditText) base2.findViewById(R.id.editphone);
    }
        return editphoneBox;
    }
    public String getEditBoxText()
             {
                return getEditBoxField().getText().toString();

             } 

}


got it working .. all i had to do is call is findViewById() on alertdialog object and call setText there code goes like this

EditText ed=(EditText) editDialog.findViewById(R.id.editphone); ed.setText("1234");

thanks anyways

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号