单选题里会用到radiobutton,如果不想使用系统提供的圆圈样式,可以自定义样式,想要做成的效果就是,

使用自定义的图片替换圆圈,然后选择有4个选项的其中一个,图片上有个对勾标记,

然后如果正确选项是帅哥,则选择A后,图片替换成

所以首先在xml属性里,将自定义的图片替换圆圈:关键就是

 android:button="@drawable/c" 这一句:
  <RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="丑男"
android:button="@drawable/c" />

然后在代码中设置监听事件,当选中了正确答案,

rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
result = (RadioButton)findViewById(checkedId);
if (result.getText().toString().equals("帅哥"))
{
result.setButtonDrawable(R.drawable.b1);//选对后替换打钩的图片 resultDetail.setVisibility(View.VISIBLE);
resultDetail.setText("恭喜你,答对了!"); }else {
resultDetail.setVisibility(View.VISIBLE);
resultDetail.setText("很遗憾,答错了!");
} }
});

最新文章

  1. Java(接口与继承)动手动脑
  2. c++ http请求
  3. MindFusion Pack for ASP.NET发布v2013.R2
  4. Android项目中单实例数据库类,解决database is locked
  5. 换一换js
  6. Stanford CoreNLP--Named Entities Recognizer(NER)
  7. jSP的3种方式实现radio ,checkBox,select的默认选择值。
  8. Reflux 使用教程
  9. 【DSA MOOC】有序向量二分查找的三个 版本
  10. LSM树由来、设计思想以及应用到HBase的索引(转)
  11. Git 使用初体验
  12. mysql的 charset、collation、prefix了解
  13. 老李分享: 并行计算基础&amp;编程模型与工具 2
  14. [Android]上传到多个Maven仓库的Gradle插件RapidMavenPushPlugin
  15. 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;goodsController&#39; defined in file [D:\eclipse\eclipse-space\pinyougou_parent\pinyou
  16. Nodejs nmp 常用命令
  17. sublime text3 license
  18. corePoolSize和maxPoolSize的区别
  19. NOIP2017提高组预赛详解
  20. lca tarjin

热门文章

  1. Ubuntu 12.04和Windows 7双系统安装图解
  2. 干货分享:MySQL之化险为夷的【钻石】抢购风暴【转载】
  3. windows加固方案
  4. apt
  5. 关于svn的安装问题
  6. zf-监察系统的左侧菜单树的表
  7. constraint 摘自群主大大
  8. docker入门实战笔记
  9. 在Gridview编辑时添加DropDownList控件并设置默认值
  10. sql server 修改表结构