2012-11-27 3 views
0

사용자가 장치에서 뒤로 버튼을 클릭 할 때 호출되는 경고 대화 상자가 있지만이 경고가 너무 짧고 사용자가 그 안에 아무것도 읽지 않거나 아무 것도 읽을 수없는 경우 호출됩니다.알림 대화 상자의 길이가 짧음

AlertDialog alertDialog = new AlertDialog.Builder(birthDate.this).create(); 
        // Setting Dialog Title 
        alertDialog.setTitle("Alert Dialog"); 
        // Setting Dialog Message 
        alertDialog.setMessage("Welcome to AndroidHive.info"); 
        // Setting OK Button 
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
        // Write your code here to execute after dialog closed 
        Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_LONG).show(); 
        } 

나는 더 이상이 경고 대화

+0

당신은 토스트 나 alertDialog의 기간을 의미합니까? alertdialog는 여기에서 코드를 닫지 않으므로 (dismiss() 메소드를 호출하지 않았 음), 축배에 대해 duration의 param을 10000ms (10 초)로 지정할 수 있습니다. – Houcine

+0

이것을 살펴보십시오 http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long – user1840039

+0

경고 대화 또는 토스트에 대해 말하는 날씨를 설명 할 수 있습니까? – Sameer

답변

1

난 당신이 모두 같은 시간에 있습니다에 AlertDialog와 finish()를 호출 생각의 시간을 만들고 싶어. 난 당신이 경고 대화 버튼의 클릭에 표시지고있는 Toast에 대해 물어 여기에 있다고 가정하고

alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
       // Write your code here to execute after dialog closed 
       Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_LONG).show(); 
       finish();// here calling finish if user click ok button. 
       } 
+1

관련 답변이 없습니다. 한 번에 두 가지 일을 할 수있는 방법. 그것은 불가능합니다. – Sameer

+0

둘 다 시간에 경고 대화 상자를 호출하는 것을 의미하고 그 아래에서 finish() 호출은 경고 대화 상자를 표시하고 즉시 finish()가 호출하여 작업이 이동하도록합니다. –

+0

그러면 Window Leak 예외가 발생하고 응용 프로그램이 충돌합니다. – Sameer

0

으로 경고 대화 상자에서 활동을 마무리하려고합니다. 당신은 Toast의 지속 시간을 증가시킴으로써 그렇게 할 수 있습니다. Toast.LENGTH_LONG을 원하는 기간 (밀리 초) 으로 바꿉니다.

Ex.

Toast.makeText(getApplicationContext(), "You clicked on OK", 5000).show(); 
1

내 대답은 내가 다시 대화를 기각 이상

long time=System.currentTimeMillis(); 
Show Dialog 

를이 경고 대화의 시간을 만들고 싶어 요점 를 참조 long time2=System.currentTimeMillis(); 그래서 time2-time1하여 원하는 시간

업데이트 됨

장치의 뒤로 누름 버튼을 클릭하면 AlertDialog가 닫히고 AlertDialog 취소 가능 false가 표시됩니다.

0

아래 코드를 시도하십시오. 이렇게하면 경고 대화 상자를 표시 할 수있는 충분한 시간이 제공됩니다. 3 초를 매개 변수로 입력하면 요구 사항에 따라 변경할 수 있습니다.

@Override 
public void onBackPressed() { 
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); 
    AlertDialog alertDialog = dialogBuilder.create(); 
    alertDialog.setTitle("Title of your message!"); 
    alertDialog.setMessage("Your message to user"); 
    alertDialog.show(); 

    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      MainActivity.super.onBackPressed(); 
     } 
    }, 3000); 

} 
관련 문제