The*_*ter 8 android static-methods findviewbyid
我有这个静态方法:
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();
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何让第一个findViewById
玩得很好,因为它说它是一种非静态方法.我理解为什么会这么说,但必须有一个解决方法?我context
进入了这个方法,但无法一起完成它们.
归档时间: |
|
查看次数: |
13391 次 |
最近记录: |