为什么我的getSystemService显示错误The method getSystemService(String) is undefined for the type Ac
classMyClickListener3implementsView.OnClickListener{publicvoidonClick(Viewe){n...
class MyClickListener3 implements View.OnClickListener { public void onClick(View e) { notification(); } public void notification() { NotificationManager mynotification=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(); notification.icon = R.drawable.ic_launcher; notification.tickerText="疯狂JAVA"; mynotification.notify(0,notification); } }
展开
展开全部
getSystemService的方法必须在Activity类中才能调用啊,亲~
你要想在你的MyClickListener3 调用,可以把相应的activity的上下文传进去:
class MyClickListener3 implements View.OnClickListener {
private Context mContext;
public MyClickListener3(Context context) {
mContext = context;
}
public void notification() { NotificationManager mynotification=(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Activity中使用的方法:
MyClickListener3 myClickListener3 = new MyClickListener3(MyActivity.this);
mybuttion.setOnclickListener(myClickListener3);
你要想在你的MyClickListener3 调用,可以把相应的activity的上下文传进去:
class MyClickListener3 implements View.OnClickListener {
private Context mContext;
public MyClickListener3(Context context) {
mContext = context;
}
public void notification() { NotificationManager mynotification=(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Activity中使用的方法:
MyClickListener3 myClickListener3 = new MyClickListener3(MyActivity.this);
mybuttion.setOnclickListener(myClickListener3);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询