在Android中的DialogFragment中隐藏按钮 [英] Hide buttons in DialogFragment in Android
本文介绍了在Android中的DialogFragment中隐藏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我像这样实现了Dialog Fragment
I have Dialog Fragment implemented like this
public class SessionExpiredFragment extends DialogFragment {
public interface SessionExpiredFragmentListener {
public void onCancelLoginProcessPressed(DialogFragment dialog);
// validValues = true if fields are not empty and email is a valid
// email,
// else validValues = false;
public void onOKLoginProcessPressed(DialogFragment dialog,
boolean validValues);
}
SessionExpiredFragmentListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (SessionExpiredFragmentListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement SessionExpiredFragmentListener");
}
}
// UI references
private EditText mEmailView;
private EditText mPasswordView;
private View mLoginFormView;
private View mLoginStatusView;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.login_fragment_layout, null);
/*
* Get edit texts references
*/
mEmailView = (EditText) view.findViewById(R.id.email);
mPasswordView = (EditText) view.findViewById(R.id.password);
mLoginFormView = view.findViewById(R.id.login_form);
mLoginStatusView = view.findViewById(R.id.login_status);
/*
* Set builder values
*/
builder.setMessage(R.string.session_expired_title)
.setView(view)
.setPositiveButton(R.string.action_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
boolean validValues = true;
String email = mEmailView.getText().toString();
String password = mPasswordView.getText()
.toString();
if (TextUtils.isEmpty(email)
|| TextUtils.isEmpty(password))
validValues = false;
if (!isValidEmail(email))
validValues = false;
mListener.onOKLoginProcessPressed(
SessionExpiredFragment.this,
validValues);
}
})
.setNegativeButton(R.string.action_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
mListener
.onCancelLoginProcessPressed(SessionExpiredFragment.this);
}
});
return builder.create();
}
,它具有正"和负"按钮.我需要做的是在按下正向"按钮时将其隐藏.我使用了这个监听器,所以我可以监听我的活动,但这也无济于事.如何(以及在何处添加该代码)隐藏按钮?感谢您的帮助.
and it has Positive and Negative buttons. What I need to do is to hide them when Positive button is pressed. I use this Listener, so I can listen in my activity that, but that didn't help me either. HOW (and WHERE to add that code) to hide buttons? Thanks for the help.
推荐答案
Button negativeButton = alert.getButton(AlertDialog.BUTTON_NEGATIVE);
buttonNo.setEnabled(false);
这篇关于在Android中的DialogFragment中隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文