我想在静态类中显示 Toast 消息,但这是 Toast 消息参数传递应用程序上下文的问题。请帮助我,如何在静态类中显示 toast 消息。请推荐我需要做的改变,我将非常感谢你。这是我的代码的一部分。
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.training_four_position);
mEndlessRunnable = (Runnable) new UpdateRunnable();
mEndlessRunnable.run();
}
private static class UpdateRunnable implements Runnable {
private int mState;
public UpdateRunnable(Handler handler, Button[] buttons) {
mHandler = handler;
mButtons = buttons;
}
public void run() {
switch (mState) {
case 0:
mState = 1;
break;
case 1:
mState = 0;
// Here is the issue in my toast message
Toast.makeText(CONTEXT, "Toast message.",Toast.LENGTH_LONG).show();
break;
}
mHandler.postDelayed(this,1000));
}// End of run()
}//End of class UpdateRunnable
} //End of MainActivity