基本控件:checkbox,radio,日期选择器,时间选择器

1.radio时要用radiogroup

<RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnChooseTime"
        android:layout_marginTop="55dp"
        android:id="@+id/relativeLayout">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A.印度洋"
            android:id="@+id/rbA"
            android:textAllCaps="false"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp"
            android:layout_gravity="center_horizontal" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="B.大西洋"
            android:id="@+id/rbB"
            android:layout_gravity="center_horizontal" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="提交"
            android:id="@+id/btnSubmit"
            android:layout_below="@+id/rbD"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_horizontal" />


    </RadioGroup>


2. 日期与时间的用法


接口:

, DatePickerDialog.OnDateSetListener
, TimePickerDialog.OnTimeSetListener


启动日期,时间选择器

case R.id.btnChooseDate:
                new DatePickerDialog(getActivity(),this,2015,3,10).show();//2015,3,10是打开时 显示的日期.
                break;
case R.id.btnChooseTime:
                new TimePickerDialog(getActivity(),this,0,0,true).show();//0.0是打开时的时间,trur是24小时格式
                break;


接口实现:
 /**
     * @param view        The view associated with this listener.
     * @param year        The year that was set.
     * @param monthOfYear The month that was set (0-11) for compatibility
     *                    with {@link Calendar}.
     * @param dayOfMonth  The day of the month that was set.
     */
    @Override
    //DatePickerDialog的回调
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        String s = String.format("%d-%d-%d",year,monthOfYear+1,dayOfMonth);
        btnChooseDate.setText(s);
    }

    /**
     * @param view      The view associated with this listener.
     * @param hourOfDay The hour that was set.
     * @param minute    The minute that was set.
     */
    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        String s = String.format("%d:%d",hourOfDay,minute);
        btnChooseTime.setText(s);
    }


3.checkbox的接口

CompoundButton.OnCheckedChangeListener
回调函数
/**
     * Called when the checked state of a compound button has changed.
     *
     * @param buttonView The compound button view whose state has changed.
     * @param isChecked  The new checked state of buttonView.
     */
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    <span style="white-space:pre">	</span>//...
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值