我創建這個自定義AlertDialog.Builder
不能打電話解僱()上的自定義AlertDialog.Builder
的問題是我想關閉它在onClick
mPositiveBTN
的
dismiss()
和cancel()
在沒有定義!怎麼做?
這是它:
public class SendSmsDialog extends AlertDialog.Builder {
private TextView mMessageTV;
private Button mPositiveBTN;
private EditText mobileNumberET;
private Context mContext;
public SendSmsDialog(@NonNull Context context, String title, String message) {
super(context);
mContext = context;
LayoutInflater inflater = ((MainActivity)context).getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.send_sms_dialog, null);
this.setView(dialoglayout);
bindViews(dialoglayout);
setListeners();
this.setTitle(title);
mMessageTV.setText(message);
}
private void setListeners() {
mPositiveBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mobileNumberET.setEnabled(true);
mobileNumberET.requestFocus();
if (UtilitiesMethods.checkEnteredPhone(mobileNumberET.getText().toString())) {
((MainActivity)mContext).doSendSMS(mobileNumberET.getText().toString());
} else {
SendSmsDialog.this.dismiss(); //not defined
mobileNumberET.setError("Please enter a correct mobile number");
}
}
});
}
private void bindViews(View dialoglayout) {
mMessageTV = (TextView) dialoglayout.findViewById(R.id.msg_tv);
mPositiveBTN = (Button) dialoglayout.findViewById(R.id.proceed_btn);
mobileNumberET = (EditText) dialoglayout.findViewById(R.id.mobile_num);
}
}
太棒了,工作!太好了謝謝 :) –