0

I have a sax parser which runs when the user taps a start button. I would like to set a progress bar view which will update as the parser progresses.

My code is currently as follows :

public void onCreate (Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.progressview);

    try {
        XMLParser.parse(getAssets().open("deindexed.xml"), this);
    } catch (IOException e) {
        Log.d("XML","onCreate(): parse() failed");
        return;
    }

    //Start the Main Activity.
    System.out.println("Activity recreated");
    Intent i = new Intent(this, Simple.class);
    startActivity(i);

}

The problem is that the setContentView does not update until the parser has completed (which I understand is to be expected).

Can anyone advise me on the best way to transform the above so it runs using a thread ?

Thank you.

4

1 に答える 1

1

ASyncTasksをチェックしてください。または、実際のスレッドを使用し、ハンドラーを使用してメッセージをやり取りします。ASyncTasksの使用は通常、より簡単でわかりやすいですが、スレッドほど用途が広い場合もありません。XMLパーサーの場合、ASyncTaskは正常に機能するはずです。

于 2012-05-24T13:55:15.217 に答える