寫了一個會話框,讓它在點擊確定時輸出輸入框中的東西,但是一點擊確定就閃退了。
之後發現是因爲它不知道要去這個會話框所在的佈局文件中去找輸入框。
@SuppressLint("ResourceType")
protected void setCustomDialog() {
setTheme(R.style.AppTheme2);
builder=new QMUIDialog.CustomDialogBuilder(this);
builder.setLayout(R.layout.add_task)
.setTitle("待辦事項")
.addAction("取消", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
dialog.dismiss();
}
})
.addAction("確定", new QMUIDialogAction.ActionListener() {
@Override
public void onClick(QMUIDialog dialog, int index) {
EditText task=dialog.findViewById(R.id.task);
task_name=task.getText().toString();
SeekBar seekBar = dialog.findViewById(R.id.seekBar);
time=seekBar.getProgress();
Log.d("time:",time+"");
Log.d("task:", task_name);
// Toast.makeText(LoginActivity.this,taskname, LENGTH_SHORT);
dialog.dismiss();
}
});
}
因爲以前找控件時都是用findViewById的,因爲那時的控件都是在該活動的佈局文件中的,而這次是在另一個佈局文件中,所以要使用dialog.findViewById()