我有这个静态方法:
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
进入这个方法,但无法一起解决它们。
您可以做的一件事是将视图设为类范围变量并使用它。我实际上并不建议这样做,但如果你需要一些快速而肮脏的东西,它会起作用。
将视图作为参数传递将是首选方式
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)