Pau*_*aul 2 android loading http-post progressdialog
我正在尝试在启动新活动时添加进度对话框,该活动必须等待来自互联网的响应.目前屏幕在等待时变黑.有没有人知道它需要放在哪里工作?
这个进程对话:
ProgressDialog dialog = ProgressDialog.show(SearchActivity.this, "", "Loading. Please wait...", true);
dialog.dismiss();
Run Code Online (Sandbox Code Playgroud)
这是在overlayActivity扩展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;
}
Run Code Online (Sandbox Code Playgroud)
这是个人资料活动:
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
}
}
Run Code Online (Sandbox Code Playgroud)
Wal*_*ain 11
您应该使用进度对话框."配置文件"活动中应使用"进度"对话框.您可以使用以下代码:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14576 次 |
| 最近记录: |