• CheckBox


     

    Activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:tools="http://schemas.android.com/tools"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:orientation="horizontal"

        android:paddingBottom="@dimen/activity_vertical_margin"

        android:paddingLeft="@dimen/activity_horizontal_margin"

        android:paddingRight="@dimen/activity_horizontal_margin"

        android:paddingTop="@dimen/activity_vertical_margin"

        tools:context="com.example.checkbox.MainActivity" >

     

       

        <CheckBox

            android:id="@+id/checkBox1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginTop="10dp"

            android:text="已婚" />

     

    </LinearLayout>

    MainActivity.java

    package com.example.checkbox;

     

    import android.os.Bundle;

    import android.support.v7.app.ActionBarActivity;

    import android.view.Menu;

    import android.view.MenuItem;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    import android.widget.CheckBox;

    import android.widget.CompoundButton;

    import android.widget.CompoundButton.OnCheckedChangeListener;

    import android.widget.Toast;

     

    public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{

    CheckBox cb;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    cb=(CheckBox) findViewById(R.id.checkBox1);

    cb.setOnCheckedChangeListener(this);

    }

    @Override

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    if(isChecked){

    //获取CheckBox的文本内容

    String str=cb.getText().toString();

    Toast.makeText(this, str, Toast.LENGTH_LONG).show();

    }

    }

     

     

    }

     

     

     

  • 相关阅读:
    java当前时间
    @Repository、@Service、@Controller 和 @Component
    spring mvc controller间跳转 重定向 传参
    MVC思想
    AJAX
    MySQL优化大总结
    MySQL数据库优化
    java JDBM2 的几个简单实例
    集群环境下如何防止定时任务重复执行?
    Java应用集群下的定时任务处理方案(mysql)
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7931768.html
Copyright © 2020-2023  润新知