-2
ダイアログがロードされるたびにEditTextにテキストを設定するのに問題があります。onClickイベントの前にAlertDialogでテキストを変更する方法
問題は、ダイアログウィンドウが表示されるたびに、編集可能な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();
}
}