网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android单选按钮,android单选按钮选中事件

android单选按钮

你要当成单选的一组的radiobutton要放在radioGROUP下,不然这个GROUP就没起作用

创新互联2013年至今,是专业互联网技术服务公司,拥有项目成都网站设计、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元辉县做网站,已为上家服务,为辉县各地企业和个人服务,联系电话:13518219792

只有这样写,才能实现这组radiobutton是单选的效果。

android listview单选如何获取当前选中是否勾选

1、使用checked属性判断选中,代码为if($(this).attr("checked")){alert("选中了");}。

2、jquery获取radio单选按钮的值。以上就是androidlistview单选获取勾选当前选中指的方法。

求 android RadioButton属性详解

一: 单选按钮RadioButton在Android平台上也应用的非常多,比如一些选择项的时候,会用到单选按钮,实现单选按钮由两部分组成,也就是RadioButton和RadioGroup配合使用

RadioButton的单选按钮;

RadioGroup是单选组合框,用于将RadioButton框起来;

在没有RadioGroup的情况下,RadioButton可以全部都选中;

当多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个;

注意:单选按钮的事件监听用setOnCheckedChangeListener来对单选按钮进行监听

例子:一道选择题,选择哪个城市美女最多,当然,这个就是为了测试

Java代码

1.package org.loulijun.radio;

2.

3.import android.app.Activity;

4.import android.os.Bundle;

5.import android.view.Gravity;

6.import android.widget.RadioButton;

7.import android.widget.RadioGroup;

8.import android.widget.TextView;

9.import android.widget.Toast;

10.

11.public class RadioTest extends Activity {

12. /** Called when the activity is first created. */

13. TextView textview;

14. RadioGroup radiogroup;

15. RadioButton radio1,radio2,radio3,radio4;

16. @Override

17. public void onCreate(Bundle savedInstanceState) {

18. super.onCreate(savedInstanceState);

19. setContentView(R.layout.main);

20. textview=(TextView)findViewById(R.id.textview1);

21. radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);

22. radio1=(RadioButton)findViewById(R.id.radiobutton1);

23. radio2=(RadioButton)findViewById(R.id.radiobutton2);

24. radio3=(RadioButton)findViewById(R.id.radiobutton3);

25. radio4=(RadioButton)findViewById(R.id.radiobutton4);

26.

27. radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

28.

29. @Override

30. public void onCheckedChanged(RadioGroup group, int checkedId) {

31. // TODO Auto-generated method stub

32. if(checkedId==radio2.getId())

33. {

34. DisplayToast("正确答案:"+radio2.getText()+",恭喜你,回答正确!");

35. }else

36. {

37. DisplayToast("请注意,回答错误!");

38. }

39. }

40. });

41. }

42. public void DisplayToast(String str)

43. {

44. Toast toast=Toast.makeText(this, str, Toast.LENGTH_LONG);

45. toast.setGravity(Gravity.TOP,0,220);

46. toast.show();

47. }

48.}

strings.xml文件

Xml代码

1.?xml version="1.0" encoding="utf-8"?

2.resources

3. string name="hello"哪个城市美女多?/string

4. string name="app_name"单选按钮测试/string

5. string name="radiobutton1"杭州/string

6. string name="radiobutton2"成都/string

7. string name="radiobutton3"重庆/string

8. string name="radiobutton4"苏州/string

9./resources

main.xml文件:注意,这里面,4个RadioButton包含在RadioGroup中

Xml代码

1.?xml version="1.0" encoding="utf-8"?

2.LinearLayout xmlns:android=""

3. android:orientation="vertical"

4. android:layout_width="fill_parent"

5. android:layout_height="fill_parent"

6.

7.TextView

8. android:layout_width="fill_parent"

9. android:layout_height="wrap_content"

10. android:text="@string/hello"

11. android:id="@+id/textview1"

12. /

13. RadioGroup

14. android:id="@+id/radiogroup1"

15. android:layout_width="wrap_content"

16. android:layout_height="wrap_content"

17. android:orientation="vertical"

18. android:layout_x="3px"

19.

20. RadioButton

21. android:id="@+id/radiobutton1"

22. android:layout_width="wrap_content"

23. android:layout_height="wrap_content"

24. android:text="@string/radiobutton1"

25. /

26. RadioButton

27. android:id="@+id/radiobutton2"

28. android:layout_width="wrap_content"

29. android:layout_height="wrap_content"

30. android:text="@string/radiobutton2"

31. /

32. RadioButton

33. android:id="@+id/radiobutton3"

34. android:layout_width="wrap_content"

35. android:layout_height="wrap_content"

36. android:text="@string/radiobutton3"

37. /

38. RadioButton

39. android:id="@+id/radiobutton4"

40. android:layout_width="wrap_content"

41. android:layout_height="wrap_content"

42. android:text="@string/radiobutton4"

43. /

44. /RadioGroup

45./LinearLayout

二:Android 自定义RadioButton的样式(和上面关系不大)

我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式。

最近用到RadioButton,利用xml修改android:background="@drawable/button_drawable",其中button_drawable为自己定义的.xml文件(res/drawable文件下),但是不成功,到网上查找,也没有正确的说法,我就开始自己尝试,最后做好了。

其实方法很简单,同样在res/drawable新建radiobutton.xml如下

Xml代码

1.selector xmlns:android=""

2.

3. item

4.

5.

6. android:state_enabled="true"

7.

8. android:state_checked="true"

9.

10. android:drawable="@drawable/check" /

11.

12. item

13.

14. android:state_enabled="true"

15.

16. android:state_checked="false"

17.

18. android:drawable="@drawable/checknull" /

19.

20. /selector

check和checknull分别为选中和位选中的图片。

然后在你的布局文件中,RadioButton 布局

设置android:button = "@drawable/radiobutton",就可以了!


当前标题:android单选按钮,android单选按钮选中事件
网页URL:http://bjjierui.cn/article/dsejshc.html

其他资讯