2012-06-28 4 views
0

안녕하세요 android가 새로 왔습니다. 로그인 버튼을 클릭하면 인증 여부를 확인하는 웹 서비스를 호출하는 메커니즘에 로그인합니다. 그 동안 결과가 서비스에서 돌아 오지 않는 한 진행률 표시 줄이 표시되어야하고 결과가 나타나면 진행 대화 상자가 사라져야하고 성공적으로 로그인 한 다른 활동으로 이동해야합니다. 그렇지 않은 경우 잘못된 메시지가 표시됩니다. 사용자 이름과 비밀번호. 또한 취소 버튼을 표시하여 인증에 오래 걸리면 대화 상자를 닫을 수있는 옵션이 표시됩니다. 나는 이것을 시도했지만 오류가 발생했습니다. 진행 대화 상자가 표시되지 않습니다.

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.login); 

    Button btn_logIn = (Button)findViewById(R.id.btn_signIn); 
    btn_logIn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View view) { 

      ProgressDialog dialog = new ProgressDialog(getBaseContext()); 
      dialog.setMessage("Please Wait. Your authentication is in progress"); 
      dialog.setButton("Cancel", new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) {       
        dialog.dismiss();      
       } 
      }); //end of anonymous class 

      dialog.show();    
     }   
    }); //end of anonymous class  
} //end of onCreate() 

내가 로그인 버튼을 클릭

는 내가 메시지 것을 힘 가까운 응용 프로그램를 얻을. 내가 developer.android.com에 그 읽기 때문에

Opening a progress dialog can be as simple as calling ProgressDialog.show(). For 
example, the progress dialog shown to the right can be easily achieved without 
managing the dialog through the onCreateDialog(int) callback, as shown here: 

ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", 
        "Loading. Please wait...", true); 

그것이 진행 대화 상자에 대한)이 onCreateDialog을 (사용할 필요 말을하지를 참조하는 onCreateDialog(int id) 방법을 사용하지 않았다. without managing the dialog through the onCreateDialog(int) callback. 내 경우에는 대화 상자를 어떻게 표시 할 수 있습니까? 감사

+0

시도 위의 제안, 그것은 worked.Why :) ' –

+0

덕분에 지금 getBaseContext와 협력 대신'새해서 ProgressDialog가 (getBaseContext())의'()? 또한 나는 취소 버튼을 클릭하여 물어보고 싶습니다. dismiss()를 호출해도 괜찮습니까? 아니면 cancel()을 호출해야합니까? 감사 – Basit

답변

0

유 getBaseContext (와 UR 대화를 원하는 경우) 중 하나

ProgressDialog dialog = new ProgressDialog(view.getBaseContext()); 

또는

ProgressDialog dialog = new ProgressDialog(view.getContext()); 

또는

ProgressDialog dialog = new ProgressDialog(view.getApplicationContext()); 

다른 방법은 사용하는 것보다이 관련

`새해서 ProgressDialog (YOUR_CURRENT_ACTIVITY.this)를 사용하여

ProgressDialog dialog = new ProgressDialog(YourRecentActivity.this); 
관련 문제