2012-01-28 3 views
1

비동기 작업이있는 진행 대화 상자가 표시됩니다.현지화 진행 대화 상자

private class RetrieveTask extends AsyncTask<String, Void, String> 
{ 
    RetrieveTask t = this; 
    ProgressDialog d = null; 

    @Override 
    protected void onPreExecute() 
    { 
     // TODO 
     //d = ProgressDialog.show(context, "", context.getString(R.string.querying_server), true, true, new DialogInterface.OnCancelListener() { 
     d = ProgressDialog.show(context, "", "Loading...", true, true, new DialogInterface.OnCancelListener() { 
       public void onCancel(DialogInterface dialog) { 
       t.cancel(true); 
     } 
     }); 
    // continues.... 

이 단계까지 context이 루트 활동으로 설정되었습니다.

"TODO"다음의 설명에 표시된대로 메시지를 현지화하고 싶습니다. 이렇게하려면 문자열 리소스에 접근해야합니다. 여기에서 어떻게하면 좋을까요?

답변

2

나는 getResources() 전화를 누락, 그게 전부입니다.

context.getResources().getString(R.string.my_string_id);

0

그냥 활동 활동 컨텍스트에 대한 참조를 사용합니다.

예 의사 코드 :

public class MyMainActivity extends Activity { 

    private void MethodA{ 
     new RetreiveTask().execute(); 
    } 

    //then in the AsyncTask, you could get a context by using the: *MyMainActivity.this* syntax. 

    private class RetrieveTask extends AsyncTask<String, Void, String> 
    { 
     RetrieveTask t = this; 
     ProgressDialog d = null; 

     @Override 
     protected void onPreExecute() 
     { 
      // TODO 
      //d = ProgressDialog.show(context, "", context.getString(MyMainActivity.this.R.string.querying_server), true, true, new DialogInterface.OnCancelListener() { 
      d = ProgressDialog.show(context, "", "Loading...", true, true, new DialogInterface.OnCancelListener() { 
        public void onCancel(DialogInterface dialog) { 
        t.cancel(true); 
      } 
      }); 

    } 



    } 
+0

감사합니다. 그러나 작업은 알고있는 활동에서 수행되지 않습니다. – SK9

관련 문제