I am trying to add a progress dialog when a new activity is launched that has to wait for a response from the internet. At the moment the screen just goes black while it is waiting. Does any one know where it needs to be placed to work?
this progressDialog:
ProgressDialog dialog = ProgressDialog.show(SearchActivity.this, "", "Loading. Please wait...", true);
dialog.dismiss();
this is in the overlayActivity extends ItemizedOverlay:
@Override
protected boolean onTap(int index) {
final OverlayItem item = (OverlayItem) items.get(index);
final Context mContext = context;
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(item.getTitle())
.setCancelable(true)
.setPositiveButton("View Details", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(mContext, Profile.class);
intent.putExtra("id", item.getSnippet());
mContext.startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
and this is the Profile activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
Bundle extras = getIntent().getExtras();
String id;
if (extras != null) {
id = extras.getString("id");
String xml = XMLfunctions.getXMLFromBarId(id); // makes httpPost call
Document doc = XMLfunctions.XMLfromString(xml);
NodeList nodes = doc.getElementsByTagName("result");
Element e = (Element)nodes.item(0);
// rest of profile created here
}
}
You should use Progress dialog. Progress dialog should be used in the Profile activity. You can use the following code:
final ProgressDialog dialog = ProgressDialog.show(MyProfileActivity.this, "","Loading..Wait.." , true);
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
//your code here
dialog.dismiss();
}
}, 3000); // 3000 milliseconds