【Android程式碼片段03】獲取對話方塊中輸入的內容
阿新 • • 發佈:2019-02-07
//點選按鈕出現對話方塊,輸入內容,並將內容獲取在全域性變數中
case R.id.card:
final EditText filename = new EditText(this);
filename.setInputType(EditorInfo.TYPE_CLASS_PHONE);//設定輸入時是數字鍵盤
Builder alerBuidler = new Builder(this);
alerBuidler
.setTitle("請輸入工號")
.setView(filename)
.setPositiveButton("確定" ,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
idcard = filename.getText().toString();
}
});
aler = alerBuidler.create();
aler.setCanceledOnTouchOutside(false );
aler.show();
break;