これは初歩的な質問かもしれませんが、なぜコンストラクターではなく Toast を作成するために静的メソッド (makeText) を使用しなければならないのか疑問に思っていました。
なぜこれを使用する必要があるのですか:
makeText(Context context, CharSequence text, int duration)
これの代わりに:
new Toast(Context context, CharSequence text, int duration)
これは makeText メソッドです:
public static Toast makeText(Context context, CharSequence text, int duration) {
Toast result = new Toast(context);
LayoutInflater inflate = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
result.mNextView = v;
result.mDuration = duration;
return result;
}
なぜ私たちは次のものを持っていないのですか:
public Toast (Context context, CharSequence text, int duration) {
this(context);
LayoutInflater inflate = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
this.mNextView = v;
this.mDuration = duration;
}
何らかの理由で Web とソース コードを検索しましたが、見つかりませんでした。
アイデアがあれば、遠慮なくどうぞ。