Android: Process Dialog cycle through different strings
I was wondering if it would be possible when I have a process dialog thread pop-up to have text able to cycles through a series of different strings. Kind of like the old SimCity games when you created a new city it would say: "Building TeraF开发者_运维问答orming Populating etc."
haha Not the best example but that is the first thing that comes to mind. I use this for a basic dialog:
private class LoadingThread extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
try {
Thread.sleep(8000);
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
new AlertDialog.Builder(MyClass.this)
.setMessage(result).setCancelable(false).setTitle("Title")
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Sorry.", Toast.LENGTH_LONG).show();
}
}
).show();
}
}
Its called with:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.progressDialog =
ProgressDialog.show(
this,
"String 1",
"String 2"
);
new LoadingThread().execute();
}
I would suggest against using a timer as loading time is never constant. Instead , depending on what you are loading , use the progress percentage to change the title or text .
精彩评论