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.
Check out ASyncTasks. Or, use real Threading and use a Handler to pass messages back/forth. Using ASyncTasks is usually easier/neater, but sometimes it cannot be as versatile as a Thread. For your XML parser, an ASyncTask should work fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.