나는 쉐이커가 있고 쉐이크 모션에 대화 상자를 표시하려고합니다. 여러 번 흔들어서 문제가 생기면 여러 개의 대화 상자가 표시됩니다. 나는 한 번에 하나의 대화 상자 만 보여주고 싶다.대화 상자가 표시되면 안드로이드
그래서이 코드를 작성했지만 오류가 있습니다. 한 줄은 "마지막에 AlertDialog"를 원하고 다른 라인은 "최종"
public void onShake() {
final AlertDialog builder = null;
if(!builder.isShowing()){
builder = new AlertDialog.Builder(getParent()).create(); -- error if final is casted on AlertDialog -- "The final local variable builder cannot be assigned. It must be blank and not using a compound assignment"
builder.setTitle("Shake");
builder.setButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
builder.dismiss(); -- requires final AlertDialog -- "Cannot refer to a non-final variable builder inside an inner class defined in a different method"
}
});
builder.show();
}}
편집없이 원하는 : 감사합니다, dialog.builder(); 보이는 군. 하지만 지금은 새로운 문제에 직면 해 있습니다 - NullPointerException, 경고 대화 상자가 표시되는지 여부를 확인합니다. 지금 노력하고 메신저 :
if(builder.isShowing() == false)
이 dialog.dismiss()
에 NullPointerException이
if(builder == null){
builder.setButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
dialog.dismiss();
builder = null;
}
}
이것은 정상적으로 보이지만 제 편집을 볼 수 있습니다. –
대화 상자를 한 번만 만들면 카메라가 만들어 졌는지 확인할 수 있고, 그렇다면 표시되는 경우 –
사용자가 첫 번째 대화 상자를 닫고 다시 흔들면 다른 대화 상자를 사용할 수 있기를 원하기 때문에 실망한다고 생각합니다. . –