android 显示进度,progressdialog-如何在Android中显示进度对话框?
progressdialog-如何在Android中显示进度对话框?
当我单击“登录”按钮时,我想显示ProgressDialog,这需要时间才能移动到另一个页面。 我怎样才能做到这一点?
16个解决方案
95 votes
ProgressDialog pd = new ProgressDialog(yourActivity.this);
pd.setMessage("loading");
pd.show();
这就是您所需要的。
Jave answered 2020-02-04T18:40:11Z
48 votes
您最好尝试使用AsyncTask
示例代码-
private class YourAsyncTask extends AsyncTask {
private ProgressDialog dialog;
public YourAsyncTask(MyMainActivity activity) {
dialog = new ProgressDialog(activity);
}
@Override
protected void onPreExecute() {
dialog.setMessage("Doing something, please wait.");
dialog.show();
}
@Override
protected Void doInBackground(Void... args) {
// do background work here
return null;
}
@Override
protected void onPostExecute(Void result) {
// do UI work here
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}
在登录按钮活动中使用上面的代码。 并且,请执行ProgressDialog和AsyncTask中的操作
更新:
ProgressDialog与AsyncTask集成在一起,因为您说您的任务需要时间来处理。
更新:
自27 API起不推荐使用ProgressDialog类
Praveenkumar answered 2020-02-04T18:39:50Z
21 votes
要使用ProgressDialog,请使用以下代码
ProgressDialog progressdialog = new ProgressDialog(getApplicationContext());
progressdialog.setMessage("Please Wait....");
要启动ProgressDialog使用
progressdialog.show();
使用ProgressDialog,以便在完成工作之前不能取消ProgressDialog。
要停止ProgressDialog,请使用以下代码(工作完成后):
progressdialog.dismiss();`
Abhishek Punia answered 2020-02-04T18:40:44Z
19 votes
关于“进度”对话框,您应该记住的一点是,您应该在单独的线程中运行它。 如果在UI线程中运行它,则不会显示对话框。
如果您不熟悉Android线程,那么您应该了解AsyncTask。 这可以帮助您实现轻松的线程。
样例代码
private class CheckTypesTask extends AsyncTask{
ProgressDialog asyncDialog = new ProgressDialog(IncidentFormActivity.this);
String typeStatus;
@Override
protected void onPreExecute() {
//set message of the dialog
asyncDialog.setMessage(getString(R.string.loadingtype));
//show dialog
asyncDialog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
//don't touch dialog here it'll break the application
//do some lengthy stuff like calling login webservice
return null;
}
@Override
protected void onPostExecute(Void result) {
//hide the dialog
asyncDialog.dismiss();
super.onPostExecute(result);
}
}
祝好运。
Jay Mayu answered 2020-02-04T18:41:18Z
6 votes
在您的activity中进行简单编码,如下所示:
private ProgressDialog dialog = new ProgressDialog(YourActivity.this);
dialog.setMessage("please wait...");
dialog.show();
dialog.dismiss();
Chirag Patel answered 2020-02-04T18:41:38Z
3 votes
声明您的进度对话框:
ProgressDialog progressDialog;
要启动进度对话框:
progressDialog = ProgressDialog.show(this, "","Please Wait...", true);
要关闭进度对话框:
progressDialog.dismiss();
Md. Ilyas Hasan Mamun answered 2020-02-04T18:42:07Z
2 votes
这是使用对话框的好方法
private class YourAsyncTask extends AsyncTask {
ProgressDialog dialog = new ProgressDialog(IncidentFormActivity.this);
@Override
protected void onPreExecute() {
//set message of the dialog
dialog.setMessage("Loading...");
//show dialog
dialog.show();
super.onPreExecute();
}
protected Void doInBackground(Void... args) {
// do background work here
return null;
}
protected void onPostExecute(Void result) {
// do UI work here
if(dialog != null && dialog.isShowing()){
dialog.dismiss()
}
}
}
Aristo Michael answered 2020-02-04T18:42:27Z
2 votes
当您调用oncreate()时
new LoginAsyncTask ().execute();
这里如何在流程中使用..
ProgressDialog progressDialog;
private class LoginAsyncTask extends AsyncTask {
@Override
protected void onPreExecute() {
progressDialog= new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please wait...");
progressDialog.show();
super.onPreExecute();
}
protected Void doInBackground(Void... args) {
// Parsse response data
return null;
}
protected void onPostExecute(Void result) {
if (progressDialog.isShowing())
progressDialog.dismiss();
//move activity
super.onPostExecute(result);
}
}
Kush answered 2020-02-04T18:42:52Z
1 votes
ProgressDialog dialog =
ProgressDialog.show(yourActivity.this, "", "Please Wait...");
V.J. answered 2020-02-04T18:43:08Z
1 votes
ProgressDialog pd = new ProgressDialog(yourActivity.this);
pd.show();
m.v.n.kalyani answered 2020-02-04T18:43:23Z
1 votes
final ProgressDialog loadingDialog = ProgressDialog.show(context,
"Fetching BloodBank List","Please wait...",false,false); // for showing the
// dialog where context is the current context, next field is title followed by
// message to be shown to the user and in the end intermediate field
loadingDialog.dismiss();// for dismissing the dialog
欲了解更多信息Android-progressDialog.show()和ProgressDialog.show()有什么区别?
cammando answered 2020-02-04T18:43:43Z
1 votes
现在,ProgressDialog已在Android O中正式弃用。我使用来自[https://github.com/Q115/DelayedProgressDialog]的DelayedProgressDialog来完成工作。
用法:
DelayedProgressDialog progressDialog = new DelayedProgressDialog();
progressDialog.show(getSupportFragmentManager(), "tag");
NinjaCowgirl answered 2020-02-04T18:44:08Z
1 votes
自API 26起不推荐使用ProgressDialog
仍然可以使用此:
public void button_click(View view)
{
final ProgressDialog progressDialog = ProgressDialog.show(Login.this,"Please Wait","Processing...",true);
}
Anish Arya answered 2020-02-04T18:44:32Z
1 votes
简单方法:
ProgressDialog pDialog = new ProgressDialog(MainActivity.this); //Your Activity.this
pDialog.setMessage("Loading...!");
pDialog.setCancelable(false);
pDialog.show();
Chathura answered 2020-02-04T18:44:52Z
0 votes
final ProgressDialog progDailog = ProgressDialog.show(Inishlog.this, contentTitle, "even geduld aub....", true);//please wait....
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Barcode_edit.setText("");
showAlert("Product detail saved.");
}
};
new Thread() {
public void run() {
try {
} catch (Exception e) {
}
handler.sendEmptyMessage(0);
progDailog.dismiss();
}
}.start();
KeTaN answered 2020-02-04T18:45:08Z
0 votes
步骤1:建立XML档案
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/btnProgress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Progress Dialog"/>
步骤2:建立SampleActivity.java
package com.scancode.acutesoft.telephonymanagerapp;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SampleActivity extends Activity implements View.OnClickListener {
Button btnProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnProgress = (Button) findViewById(R.id.btnProgress);
btnProgress.setOnClickListener(this);
}
@Override
public void onClick(View v) {
final ProgressDialog progressDialog = new ProgressDialog(SampleActivity.this);
progressDialog.setMessage("Please wait data is Processing");
progressDialog.show();
// After 2 Seconds i dismiss progress Dialog
new Thread(){
@Override
public void run() {
super.run();
try {
Thread.sleep(2000);
if (progressDialog.isShowing())
progressDialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
}
Manikanta Reddy answered 2020-02-04T18:45:32Z
android 显示进度,progressdialog-如何在Android中显示进度对话框?相关推荐
- linux中html的图片显示不出来,如何在HTML中显示原始的rgb图像
我在Linux上有一个基于C的小型照相机应用程序,具有内置的microhttpd网络服务器,该服务器向Web客户端提供捕获的jpeg. 效果很好,因为相机可以进行jpg编码,但是作为另一个选择,我需要 ...
- Linux显示txt文件,如何在Linux中显示文本文件中的某些行?
sed -n '10000000,10000020p' filename 你可能能够加快这一点: sed -n '10000000,10000020p; 10000021q' filename 在这些 ...
- 如何在MyEclipse中显示行数
转载自 如何在MyEclipse中显示行数 如何在MyEclipse中显示行数呢?myeclipse在默认情况下不显示行数时,用户可以自己设置显示行数,行数可以帮助我们方便的查看代码. 首先,打开w ...
- 微信小程序开发--如何在swiper中显示两个item以及下一个item的部分内容
如何在swiper中显示两个item以及下一个item的部分内容 我所实现的效果 我实现的代码 <!--图片轮播图--><!--要展示两个item 以及下一个item的部分内容,ci ...
- 如何在WordPress中显示链接的实时预览
Have you ever seen sites that show a live preview of links when you bring your mouse over them? That ...
- 计算机获取的系统时间是什么时间格式,【excle怎样获取当前日期格式】如何在EXCEL中显示当天的日期和时间?...
Excel中,如何用函数获取当前日期(即系统日期)的月份值? 个=month(today()). 当月=month(today()),当日=day(today()). =TODAY()获得当前日期,形 ...
- Microsoft Word 教程「7」,如何在 Word 中显示标尺?
欢迎观看 Microsoft Word 教程,小编带大家学习 Microsoft Word 的使用技巧,了解如何在 Word 中显示标尺. 在 Word 中显示标尺,选择「视图」,然后选择「标尺」. ...
- 如何在Python中显示图片?
如何在Python中显示图片? 相信很多程序员都曾经因为要在Python中显示图片而苦恼过,毕竟图像处理是数据分析和人工智能领域中的重要一环.所以,今天我们就来介绍一下Python中显示图片的方法. ...
- Microsoft Excel 教程:如何在 Excel 中显示或隐藏零值?
欢迎观看 Microsoft Excel 教程,小编带大家学习 Microsoft Excel 的使用技巧,了解如何在 Excel 中显示或隐藏零值. 在 Excel 中有时希望将零值显示为空单元格, ...
- Microsoft Excel 教程:如何在 Excel 中显示或隐藏图表图例?
欢迎观看 Microsoft Excel 教程,小编带大家学习 Microsoft Excel 的使用技巧,了解如何在 Excel 中显示或隐藏图表图例. 可以显示或隐藏图表的图例. 显示图例可以向读 ...
最新文章
- R语言使用ggplot2包和ggQC包可视化帕累托图(Pareto chart)
- centos7 xfce 中文字体输入法
- python中json方法_在python中使用JSON库(通用方法),json,的,常用
- delphi7aes加密解密与java互转_Java 加密/解密Excel
- 原生php登录注册,原生php登陆注册
- C/C++中的声明与定义
- HTML5: 利用SVG动画动态绘制文字轮廓边框线条
- Docker Mesos在生产环境的应用
- orgChart实现多重树状图结构
- 绿盟科技网络安全攻防实验室安全研究员廖新喜:Java JSON 反序列化之殇
- 小程序 设置小程序打开聊天中的素材
- 自动化测试之Appium
- 如何配置Linux ip地址
- 超链接标签 a (锚点链接)
- Oracle基础教程
- C语言练习题:小明排序(数组)
- PHPwind9.01图解安装教程 PHPwind怎么安装方法
- 利用Linux的特性恢复误删的数据文件
- 安装Markdownpad2后出现的错误(This view has crashed)解决
- 中国互联网协会恶意软件定义
热门文章
- CSR867x — 如何添加自定义AT Command
- ie9兼容css正常吗,针对IE9的CSS兼容
- 如何理解 ISO、快门、光圈、曝光这几个概念?
- [DA45] 时间序列预测上证指数
- 如何确定scrum的story之一:识别利益相关者和目标
- 运维之DNS服务器Bind9配置解析和基础示例及附带命令
- vue货币过滤器以及路由参数的使用
- 中国大学MOOC C语言程序设计(大连理工大学) 课后编程题 第五周题解(个人向仅供参考)
- 我xp电脑桌面没有计算机图标不见了,XP电脑开机后桌面图标打开方式全部不见的恢复方法...
- 系统可用性量表(SUS )