我有这个静态方法:
public static void displayLevelUp(int level, Context context) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_level_coast,
(ViewGroup) findViewById(R.id.toast_layout_root)); // this row
TextView text = (TextView) layout.findViewById(R.id.toastText);
text.setText("This is a custom toast");
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
Toast.makeText(context, String.valueOf(level), Toast.LENGTH_SHORT)
.show();
}
但是,我不知道如何让第一个findViewById
玩得很好,因为它说它是一种非静态方法。我理解它为什么这么说,但是必须有解决方法吗?我通过context
了这种方法,但无法将它们一起解决。