• 每日日报2021.4.9


    今天完成内容:

    学习andriod checkbox

    <TextView
    android:id="@+id/tvHead"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:textSize="20dp"
    android:text="CheckBox的用法" />

    <!-- 吃 -->
    <CheckBox
    android:id="@+id/cbEat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvHead"
    android:layout_marginTop="32dp"
    android:layout_toLeftOf="@+id/tvHead"
    android:text="吃" />

    <!-- 睡觉 -->
    <CheckBox
    android:id="@+id/cbSleep"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/cbSing"
    android:layout_alignBottom="@+id/cbSing"
    android:layout_marginLeft="40dp"
    android:layout_toRightOf="@+id/cbSing"
    android:text="睡觉" />

    <!-- 唱歌 -->
    <CheckBox
    android:id="@+id/cbSing"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/cbEat"
    android:layout_alignBottom="@+id/cbEat"
    android:layout_alignLeft="@+id/tvHead"
    android:layout_marginLeft="40dp"
    android:text="唱歌" />

    <!-- 显示爱好 -->
    <Button
    android:id="@+id/btnShow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/cbSing"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="36dp"
    android:text="输出"
    android:onClick="show" />

    package com.t20.CheckBox;

    import java.util.HashMap;
    import java.util.Map;

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

    public class MainActivity extends Activity implements OnCheckedChangeListener {
    private CheckBox cbEat;
    private CheckBox cbSing;
    private CheckBox cbSleep;
    private Map<String, String> like = new HashMap<String, String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 获取控件
    cbEat = (CheckBox) findViewById(R.id.cbEat);
    cbSing = (CheckBox) findViewById(R.id.cbSing);
    cbSleep = (CheckBox) findViewById(R.id.cbSleep);

    // 绑定事件
    cbEat.setOnCheckedChangeListener(this);
    cbSing.setOnCheckedChangeListener(this);
    cbSleep.setOnCheckedChangeListener(this);
    }

    /**
    * 复选框选中与不选中的事件
    */
    @Override
    public void onCheckedChanged(CompoundButton checkBox, boolean checked) {
    // TODO Auto-generated method stub
    switch (checkBox.getId()) {
    case R.id.cbEat:
    if (checked) {// 选中吃
    like.put("eat", "吃");
    } else {
    like.remove("eat");
    }
    break;
    case R.id.cbSing:
    if (checked) {// 选中唱歌
    like.put("sing", "唱歌");
    } else {
    like.remove("sing");
    }
    break;
    case R.id.cbSleep:
    if (checked) {// 选中睡觉
    like.put("sleep", "睡觉");
    } else {
    like.remove("sleep");
    }
    break;
    default:
    break;
    }
    }

    /**
    * 输出总的爱好
    *
    * @param v
    */
    public void show(View v) {
    // 循环读取爱好
    StringBuilder sb = new StringBuilder();
    String ret = "这个人的爱好是:";

    if (like.size() == 0) {
    String no = "这个人完全没有爱好!";
    Toast.makeText(MainActivity.this, no, Toast.LENGTH_SHORT).show();
    } else {
    sb.append(ret);
    for (String key : like.keySet()) {
    sb.append(like.get(key) + " ");
    }
    Toast.makeText(MainActivity.this, sb, Toast.LENGTH_SHORT).show();
    }

    }
    }

    看视频

    遇到问题:

    明日目标:

    学习Android studio的开发

  • 相关阅读:
    删除 Change Pointers
    如何提高读取BSEG的性能(sap已清项和未清项的提取) (转)
    思维导图FreeMind
    调用BAPI创建发票时报错
    BAPI for Credit Memo
    账页程序源码(PL/SQL)
    ALV Grid 行单击事件响应
    abap 读取文件的FM
    Logistics在SAP中为什么"后勤"的意思(转)
    N次笑N次据说可以让人年轻10岁的故事
  • 原文地址:https://www.cnblogs.com/leiyu1905/p/14912328.html
Copyright © 2020-2023  润新知