代碼如下,這樣獲取edittext.gettext().tostring()值總為空,該怎麼改呢?
final View viewDialog=(View)getLayoutInflater().inflate(R.layout.ad_dialog,null);
new AlertDialog.Builder(Ad_Delete.this).setTitle("請輸入刪除數量(不能大於現有本數)")
.setView(getLayoutInflater().inflate(R.layout.ad_dialog, null))
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
EditText ad_delete_edit = (EditText)viewDialog.findViewById(R.id.ad_delete_number);
int deleteNumber = Integer.parseInt(ad_delete_edit.getText().toString());
if (deleteNumber > nowNumber || deleteNumber < 0) {
Toast.makeText(Ad_Delete.this, "輸入數量有誤,請輸入不大於現有數量的數目", Toast.LENGTH_LONG).show();
} else {
sqLiteOpenHelper_ad.getReadableDatabase().execSQL("updata Administrator_inf set book_totalnumber = ?, " +
"book_nownumber = ? where _id = ?",
new Integer[]{totalNumber - deleteNumber, nowNumber - deleteNumber, id});
Toast.makeText(Ad_Delete.this, "刪除成功!", Toast.LENGTH_LONG).show();
}
}
}).show();
}
});
final View viewDialog=(View)getLayoutInflater().inflate(R.layout.ad_dialog,null);
new AlertDialog.Builder(Ad_Delete.this).setTitle("請輸入刪除數量(不能大於現有本數)")
.setView(getLayoutInflater().inflate(R.layout.ad_dialog, null))
改成
final View viewDialog=(View)getLayoutInflater().inflate(R.layout.ad_dialog,null);
new AlertDialog.Builder(Ad_Delete.this).setTitle("請輸入刪除數量(不能大於現有本數)")
.setView(viewDialog)
不然你獲取edittext的viewDialog不是dialog顯示的viewDialog