单选。多选,删除

package com.example.d924_monthexam;


import java.util.ArrayList;


import com.x.d924_monthexam.adapter.MyAdapter;
import com.x.d924_monthexam.bean.Exam;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;


public class MainActivity extends Activity implements OnClickListener {


private ListView lv;
private Button b1;
private Button b2;
private Button b3;
private ArrayList<Exam> al;
private  ArrayList<Exam> al1= new ArrayList<Exam>();
private MyAdapter ma;
private boolean isChecked=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
ma = new MyAdapter(this,al);
lv.setAdapter(ma);
}


private void initData() {
al = new ArrayList<Exam>();
al.add(new Exam("fucking month exam1",false));
al.add(new Exam("fucking month exam2",false));
al.add(new Exam("fucking month exam3",false));
al.add(new Exam("fucking month exam4",false));
al.add(new Exam("fucking month exam5",false));
al.add(new Exam("fucking month exam6",false));
al.add(new Exam("fucking month exam7",false));
al.add(new Exam("fucking month exam8",false));
al.add(new Exam("fucking month exam9",false));
al.add(new Exam("fucking month exam10",false));
al.add(new Exam("fucking month exam11",false));
al.add(new Exam("fucking month exam12",false));
}


private void initView() {
lv = (ListView) findViewById(R.id.lv);
b1 = (Button) findViewById(R.id.b1);
b2 = (Button) findViewById(R.id.b2);
b3 = (Button) findViewById(R.id.b3);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b1:
chose();
break;
case R.id.b2:
unChose();
break;
case R.id.b3:
delete();
break;


default:
break;
}
ma.notifyDataSetChanged();
}


private void chose() {
if (!isChecked) {
for (int i = 0; i < al.size(); i++) {
if (al.get(i).isChecked()==false) {
al.get(i).setChecked(true);
}
}
isChecked=true;
}else if(isChecked){
for (int i = 0; i < al.size(); i++) {
if (al.get(i).isChecked()==true) {
al.get(i).setChecked(false);
}
}
isChecked=false;
}

}
private void unChose() {
for (int i = 0; i < al.size(); i++) {
al.get(i).setChecked(!al.get(i).isChecked());
}
}


private void delete() {
for (int i = 0; i < al.size(); i++) {
if (al.get(i).isChecked()) {
al1.add(al.get(i));
}
}
al.removeAll(al1);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值