android 全选和全不选

<RelativeLayout 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: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=".MainActivity" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="26dp"
        android:text="CheckBox" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/checkBox1"
        android:layout_below="@+id/checkBox1"
        android:text="CheckBox" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/checkBox2"
        android:layout_below="@+id/checkBox2"
        android:text="CheckBox" />

    <CheckBox
        android:id="@+id/checkBox4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/checkBox3"
        android:layout_below="@+id/checkBox3"
        android:text="CheckBox" />

</RelativeLayout>
package com.example.jmj;


import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class MainActivity extends Activity {
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>private CheckBox a,b,c,d =null;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>protected void onCreate(Bundle savedInstanceState) {
<span style="white-space:pre">		</span>super.onCreate(savedInstanceState);
<span style="white-space:pre">		</span>setContentView(R.layout.activity_main);
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>a = (CheckBox)findViewById(R.id.checkBox1);
<span style="white-space:pre">		</span>b = (CheckBox)findViewById(R.id.checkBox2);
<span style="white-space:pre">		</span>c = (CheckBox)findViewById(R.id.checkBox3);
<span style="white-space:pre">		</span>d = (CheckBox)findViewById(R.id.checkBox4);
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>CheckListener checklistener = new CheckListener();
<span style="white-space:pre">		</span>d.setOnCheckedChangeListener(checklistener);
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Override
<span style="white-space:pre">	</span>public boolean onCreateOptionsMenu(Menu menu) {
<span style="white-space:pre">		</span>// Inflate the menu; this adds items to the action bar if it is present.
<span style="white-space:pre">		</span>getMenuInflater().inflate(R.menu.main, menu);
<span style="white-space:pre">		</span>return true;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>class CheckListener implements OnCheckedChangeListener{


<span style="white-space:pre">		</span>@Override
<span style="white-space:pre">		</span>public void onCheckedChanged(CompoundButton buttonView,<span style="white-space:pre">	</span>boolean isChecked) {
<span style="white-space:pre">			</span>
<span style="white-space:pre">			</span>
<span style="white-space:pre">				</span>a.setChecked(isChecked);
<span style="white-space:pre">				</span>b.setChecked(isChecked);
<span style="white-space:pre">				</span>c.setChecked(isChecked);
<span style="white-space:pre">			</span>
<span style="white-space:pre">				</span>
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值