2016-11-22 2 views
0

ProgressDialog 정적 메서드 show()의 반환 값과 해당 클래스의 인스턴스에 대한 비 정적 메서드 표시 간의 차이점은 무엇입니까? 특정 상황에 대한Android - progressDialog.show()와 ProgressDialog.show()의 차이점은 무엇입니까?

ProgressDialog pd = ProgressDialog.show(mActivity,mTitle,mMessage); 

:

이 전략이에

ProgressDialog pd = new ProgressDialog(mActivity); 
pd.setTitle(mTitle); 
pd.setMessage(mMessage); 
pd.show(); 

을 선호 할 이유가 있습니까? 자본 P와 함께 작성

답변

1

를 액세스해야한다는 것입니다. 정적 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; 
} 

당신은 볼 수 매개 변수 그냥해서 ProgressDialog를 건설 끝과 인스턴스 메소드 show()를 호출 정적 show 방법에 대한 호출.

정적 인 show(...) 메서드를 사용하면 한 줄의 코드를 사용하여 기본 ProgressDialog를 편리하게 표시 할 수 있습니다.

1

어떤 이유가을 보여 방법은

ProgressDialog.show(mActivity,mTitle,mMessage); 

이 문서 here

enter image description here

를 참조 정적이기 때문에 이동하는 올바른 방법입니다 이 전략을 선호 하는가 ??

갈 수있는 가장 좋은 방법입니다 이유는 정적 메서드는 항상 "올바른"방법은 사용량에 따라 달라 정적 방법으로 제 생각에는

+0

사실, show() 메소드는 정적이 아닙니다. 그것은 'Dialog'의 인스턴스 메소드입니다. – kurtacious

+1

의사가 정체라고 말했습니다. –

+0

오. @ ΦXocę 웃어 Пepeúpa ツ : 커다란이 맞습니다. ['Dialog'] (https://developer.android.com/reference/android/app/Dialog.html) (['ProgressDialog'의 수퍼 타입) (https://developer.android.com/reference/ android/app/ProgressDialog.html)) static이 아닌 ['show'] (https://developer.android.com/reference/android/app/Dialog.html#show()) 메소드도 존재합니다. 인자를 취하지 않는다). OP는이 두 가지 방법의 차이점을 묻습니다. – Seelenvirtuose