首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android中Notification提示添加Button事件无效,该如何处理

2012-03-24 
Android中Notification提示添加Button事件无效想在Notification提示中添加2个button,并且能点击,点击后通

Android中Notification提示添加Button事件无效
想在Notification提示中添加2个button,并且能点击,点击后通过Toast提示用户,现在Button什么都 添加 好了,但是无法为button添加onclick事件,请问应该如何操作。

看API有个setOnClickPendingIntent方法,但发现他只能实现跳转到指定Activity、或者是Service里面中,根本无法实现我想要的

分不多了,就40分吧

[解决办法]
添加OnClickListener接口并实现该接口的onClick方法

为button添加监听 下面是个小例子

public class XXX extends Activity implements OnClickListener{
Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.xx);
button.setOnClickListener(this);
}
public void onClick(View v) {
if (v.equals(buttonadd[0])) {
//这里是按下按钮后的响应代码
}
}
}

热点排行