Это может быть нубский вопрос, но мне было интересно, почему мы должны использовать статический метод (makeText )для создания Toast, а не конструктор.
Почему мы должны использовать это:
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;
}
Я искал в Интернете и исходный код по любой причине, но я не нашел.
Пожалуйста, если у вас есть идея, не стесняйтесь.