今天遇到这个问题,参考了博文 http://blog.csdn.net/ezhong0812/article/details/6277814

问题:

     layout文件定义了2个button

 

  java文件中做了不同的onClick动作,点击后触发2个不同的Activity

         Button button_send = (Button)findViewById(R.id.button_send);        button_send.setOnClickListener(new tryClickListener());                Button button2 = (Button)findViewById(R.id.button_two);        button2.setOnClickListener(new OnClickListener(){});

   运行的时候提示:应用程序xx(进程:xxx.xxx.xxx)意外停止,请重试


解决过程:

    首先参考上面的博文,将第二个button的定义修改为TextView

 

 Button button_send = (Button)findViewById(R.id.button_send);        button_send.setOnClickListener(new tryClickListener());                TextView button2 = (TextView)findViewById(R.id.button_two);        button2.setOnClickListener(new OnClickListener(){});
 这样,确实可以正常启动,没有报错。

但是有另外一个问题: 界面上只有一个button点击后有效果,button2点击后没有反应


最终,解决方法是将两个button都置成android:focusable="false",如下:

 
java文件还是使用Button定义控件:

 Button button_send = (Button)findViewById(R.id.button_send);        button_send.setOnClickListener(new tryClickListener());                Button button2 = (Button)findViewById(R.id.button_two);        button2.setOnClickListener(new OnClickListener(){});

这样就ok啦。




更多相关文章

  1. JNI开发(一)之framework层增加自定义JNI层
  2. 在Android应用中读取彩信文件
  3. android如何给apk重新签名
  4. Android(安卓)7.0 FileProvider 的那些坑
  5. Android(安卓)APK系列3-------使用platform密钥来给apk文件签名
  6. Android之简单文件管理器
  7. 谷歌开发工具Android(安卓)Studio安装使用图文教程
  8. Android(安卓): gen already exists but is not a source folder
  9. 学习Android(安卓)Studio开发工具之Activity3(框架3)

随机推荐

  1. Android中的一些方法-----生生不息
  2. java.lang.IllegalStateException: Actio
  3. Android(安卓)Handler总结1-定义与用法
  4. Android(安卓)IOS 安全书籍
  5. Android之进程查看,关闭(可操作所有进程)
  6. android 中的MultipartEntity 类
  7. Android动态权限判断以及动态权限申请
  8. android 的单例模式
  9. Android官方文档翻译 一 Getting Started
  10. android tv 实现颜色条滚动效果