2013�N11��22��

[Android] AlertDialog��getButton()��null��Ԃ�

Dialog��OK�{�^��(Positive�{�^��)�̒������𔻒肵�����āA�ȉ��̂悤�ȃR�[�h�������܂����B
Builder builder = new Builder(getActivity());
builder.setTitle("title").setMessage("message");
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});

AlertDialog dialog = builder.create();
Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});


��������s����ƁANullPointerException���������ăA�v�����ُ�I�����܂����B
11�s�ڂ�dialog.getButton()��null���ԋp����Ă��邽�߂ł��B
Web���������Ă݂�ƈȉ��̏�񂪌��‚���܂����B

Issue 6360 - android - AlertDialog getButton() return null - Android Open Source Project - Issue Tracker - Google Project Hosting

�ǂ���Dialog��\�����Ă���łȂ���null�ɂȂ��Ă��܂��悤�ł��B
�\�[�X�R�[�h��ǂ�ł݂��Dialog��onCreate()��ʂ�Ȃ��ƒ���View����������Ȃ��悤�ł���(���Ԃ�)�B
Dialog���\�����ꂽ�Ƃ����OnLongClickListener���Z�b�g���邱�Ƃɂ��܂����B


Builder builder = new Builder(getActivity());
// ... �ȗ� ...

AlertDialog dialog = builder.create();
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});
}
});


�����߂�ǂ������ł����A����Ȃ���v�ł����B
posted by t2low at 21:00| Android