2011-02-18 7 views
0

저는 ListActivity 클래스를 가지고 있으며 목록의 항목을 클릭하면 새로운 활동이 표시됩니다. 새 작업을로드하는 데 시간이 걸립니다. 그래서 사용자가 진행 상황 대화 상자의 형태로 어떤 일이 일어나고 있음을 알리고 싶습니다.Android - 진행 대화 상자가 닫히지 않습니다.

그래서 이렇게하려면 내 클래스에서 Runnable을 다음과 같이 구현했습니다. -

public class ProtocolListActivity extends ListActivity implements Runnable { 
private ProgressDialog progDialog; 
.... 
protected void onListItemClick(ListView l, View v, int position, long id) { 
        progDialog.show(this, "Showing Data..", "please wait", true, false); 

    Thread thread = new Thread(this); 
    thread.start(); 
} 
.... 
public void run() { 
    // some code to start new activity based on which item the user has clicked. 
} 

는 처음에 내가 클릭하면, 새로운 활동이로드되고 진행 대화 상자가 계속 실행되고, 진행 대화 상자가 잘 작동하지만, 내가 이전의 활동을 닫을 때 (다시이 목록을 얻기 위해). 진행률 대화 상자가 새로운 활동이 시작될 때만 나타나기를 원합니다.

누군가 올바르게 안내해 줄 수 있습니까?

답변

3

대화 상자는 프로그래머가 명시 적으로 제거하거나 사용자가 닫아야합니다. 그래서,이 방법으로 수행해야합니다 : 활동 A의

(호출 활동)

protected void onListItemClick(ListView l, View v, int position, long id) { 
    progDialog.show(this, "Showing Data..", "please wait", true, false); 

    Thread thread = new Thread(this){ 
     // Do heavy weight work 

     // Activity prepared to fire 

     progDialog.dismiss(); 
    }; 
    thread.start(); 
} 

를 대부분 사용하는 경우, 무거운 작업은 호출자의 활동에 있어야하지만. 경우, 무거운 작업은 호출자의 onCreate을 완료, 그것은해야합니다 같은 :

활동 B (수신자) :

onCreate(){ 
    progDialog.show(this, "Showing Data..", "please wait", true, false); 

    Thread thread = new Thread(this){ 
     // Do heavy weight work 

     // UI ready 

     progDialog.dismiss(); 
    }; 
    thread.start(); 
} 

어쨌든, 아이디어는 여전히 동일합니다.

관련 문제