Android - progressDialog.show() 和 ProgressDialog.show() 有什么区别?
Android - What is difference between progressDialog.show() and ProgressDialog.show()?
我的意思是,ProgressDialog 静态方法 show() 的 return 值和该 class 实例的非静态方法 show 之间有什么区别?
有什么理由更喜欢这个策略
ProgressDialog pd = new ProgressDialog(mActivity);
pd.setTitle(mTitle);
pd.setMessage(mMessage);
pd.show();
对此:
ProgressDialog pd = ProgressDialog.show(mActivity,mTitle,mMessage);
针对特定情况?
用大写 p 写是正确的方法,因为方法 show 是静态的
ProgressDialog.show(mActivity,mTitle,mMessage);
查看文档 here
Is there any reason to prefer this strategy??
最好的方法是
静态方法应始终以静态方式访问
在我看来,"correct" 方法将取决于您的使用情况。静态 show( ... )
方法执行与您相同的步骤:
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
ProgressDialog dialog = new ProgressDialog(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIndeterminate(indeterminate);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
dialog.show();
return dialog;
}
您可以看到,对静态 show
方法 和 参数的任何调用最终都会构建一个 ProgressDialog 并将调用实例方法 show()
。
使用静态show( ... )
方法只是方便您使用一行代码显示基本的ProgressDialog。
我的意思是,ProgressDialog 静态方法 show() 的 return 值和该 class 实例的非静态方法 show 之间有什么区别?
有什么理由更喜欢这个策略
ProgressDialog pd = new ProgressDialog(mActivity);
pd.setTitle(mTitle);
pd.setMessage(mMessage);
pd.show();
对此:
ProgressDialog pd = ProgressDialog.show(mActivity,mTitle,mMessage);
针对特定情况?
用大写 p 写是正确的方法,因为方法 show 是静态的
ProgressDialog.show(mActivity,mTitle,mMessage);
查看文档 here
Is there any reason to prefer this strategy??
最好的方法是 静态方法应始终以静态方式访问
在我看来,"correct" 方法将取决于您的使用情况。静态 show( ... )
方法执行与您相同的步骤:
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static ProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
ProgressDialog dialog = new ProgressDialog(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIndeterminate(indeterminate);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
dialog.show();
return dialog;
}
您可以看到,对静态 show
方法 和 参数的任何调用最终都会构建一个 ProgressDialog 并将调用实例方法 show()
。
使用静态show( ... )
方法只是方便您使用一行代码显示基本的ProgressDialog。