У меня проблемы с установкой текста в 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();
}
}