как изменить текст в AlertDialog перед событием onClick - PullRequest
0 голосов
/ 02 февраля 2011

У меня проблемы с установкой текста в EditText при каждой загрузке диалога.

Проблема в том, что всякий раз, когда появляется диалоговое окно, в тексте редактирования должен быть какой-то определенный текст, который можно редактировать. Его нельзя сделать статическим (определенным в XML), поэтому куда я должен поместить код вроде wrapper.setText("some phone number etc");?

Вот код:

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) {
                    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();

             } 

}

1 Ответ

0 голосов
/ 03 февраля 2011

получил это работает .. все, что мне нужно было сделать, это вызвать findViewById () для объекта alerttdialog и вызвать setText там код выглядит так

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

спасибо в любом случае

...