设为首页 加入收藏

TOP

[APP] Android 开发笔记 004-Android常用基本控件使用说明(七)
2017-10-13 10:47:29 】 浏览:11577
Tags:APP Android 开发 笔记 004-Android 常用 基本 控件 使用说明
   public void onCheckedChanged(RadioGroup group, int checkedId) {
                    RadioButton radbtn = (RadioButton) findViewById(checkedId);
                    Toast.makeText(getApplicationContext(), "按钮组值发生改变,你选了" + radbtn.getText(), Toast.LENGTH_LONG).show();
                }
            });

        获得RadioButton相关信息的方法:

        -getClidCont() 获得按钮组中的单选按钮的数目
        -getClindAt()  根据索引值获得单选按钮 (参数为索引值 0,1,2,3..)
        -isChecked()   判断按钮是否被选中(参数为true/false)


CheckBox复选框


    1)代码:

        <CheckBox
            android:id="@+id/checkbox"
            android:text="苹果"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/checkbox1"
            android:text="香蕉"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/checkbox2"
            android:text="大鸭梨"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    2)监听方法:

        可以同时选中多个选项,至于获得选中的值,一般是为每个CheckBox添加事件:setOnCheckedChangeListener

        public class MyActivity extends Activity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{
         
            private CheckBox cb_one;
            private CheckBox cb_two;
            private CheckBox cb_three;
            priva

首页 上一页 4 5 6 7 8 下一页 尾页 7/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android---闪频页和倒计时 下一篇微信支付仅能成功调用一次的问题

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目