学习记录(3.6)

  学习时长:9h

  代码行数:约500行

  周末包括今天一直在学习安卓应用开发。虽然没有连上数据库,但是页面跳转和页面布局已经学的差不多了,并且也学会,如何限制输入框最小字符串长度。

  今天上课,通过建民老师的教导,我意识到了代码单元测试和规范性的重要性,软件工程绝对不是自己一个人的战斗,它属于整个团队,为了更好齐心协力,代码就一定要搞好规范性,这也是之后学习的方向之一了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
        android:id="@+id/hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="每日打卡系统欢迎您"
        android:textSize="15dp"/>
        <Button
            android:id="@+id/b_tiaoguo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="跳过广告" />
    </LinearLayout>
 
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center">
        <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="广告位招租"
        android:textSize="40dp"/>
    </LinearLayout>
</LinearLayout>

  

复制代码
package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

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

        Button button = findViewById(R.id.button);
        Button button1 = findViewById(R.id.b_tiaoguo);
        button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, Main3Activity.class);
                startActivity(intent);
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent();
                intent.setClass(MainActivity.this, Main3Activity.class);
                startActivity(intent);
            }
        });
    }
}
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?xml version="1.0" encoding="utf-8"?>
<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="vertical"
    android:gravity="center">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/zhucet"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:textSize="50dp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="选择您的性别"/>
        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="男" />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="女"/>
        </RadioGroup>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/zc_id"
            android:hint="请输入用户名"
            android:inputType="text"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/zc_phone"
            android:hint="请输入手机号"
            android:inputType="text"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/zc_password"
            android:hint="请输入密码"
            android:inputType="textPassword"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="确认密码"
            android:inputType="textPassword"/>
 
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">
        <Button
            android:id="@+id/iv_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="返回"
            android:textSize="40dp" />
        <Button
            android:id="@+id/zhuceb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:textSize="40dp" />
    </LinearLayout>
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.myapplication1;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
 
public class Zhuce extends AppCompatActivity implements View.OnClickListener {
 
    private EditText zc_phone;
    private EditText zc_id;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce);
        zc_id = findViewById(R.id.zc_id);
        zc_phone = findViewById(R.id.zc_phone);
        EditText password = findViewById(R.id.zc_password);
        zc_phone.setOnFocusChangeListener(this::onFocusChange);
        password.setOnFocusChangeListener(this::onFocusChange);
        findViewById(R.id.iv_back).setOnClickListener(this::onClick);
        findViewById(R.id.zhuceb).setOnClickListener(this::onClick);
 
    }
    public void onFocusChange(View v,boolean b)
    {
        if(b){
            String phone=zc_phone.getText().toString();
            String id=zc_id.getText().toString();
            if(TextUtils.isEmpty(phone) || phone.length()<11) {
                zc_phone.requestFocus();
                Toast.makeText(this, "请输入11位手机号", Toast.LENGTH_SHORT).show();
            }
            if(TextUtils.isEmpty(id)) {
                zc_id.requestFocus();
                Toast.makeText(this, "用户名不能为空", Toast.LENGTH_SHORT).show();
            }
 
        }
    }
    public void onClick(View view) {
        if(view.getId() == R.id.iv_back || view.getId() == R.id.zhuceb)
            finish();
    }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="广告位招租"
            android:textSize="50dp"/>
    </LinearLayout>
    <Button
        android:id="@+id/b_data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="选择日期"/>
    <TextView
        android:id="@+id/tv_data"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <EditText
        android:id="@+id/tv_zhuti"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入打卡主题"
        android:inputType="text"/>
    <EditText
        android:id="@+id/tv_neirong"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="50dp"
        android:hint="请输入打卡内容"
        android:inputType="text"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Button
        android:id="@+id/b_start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="选择开始时间"/>
    <TextView
        android:id="@+id/tv_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Button
        android:id="@+id/b_end"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="选择结束时间"/>
    <TextView
        android:id="@+id/tv_end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    </LinearLayout>
    <Button
        android:id="@+id/dakaa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="打卡"/>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="广告位招租"
            android:textSize="50dp"/>
    </LinearLayout>
</LinearLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.example.myapplication1;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
 
import java.util.Calendar;
 
import bean.Bean;
import database.UserDBHelper;
import util.ToastUtil;
 
public class Daka extends AppCompatActivity implements View.OnClickListener {
 
    private TextView tv_data;
    private TextView tv_start;
    private TextView tv_end;
    private EditText tv_zhuti;
    private UserDBHelper mHelper;
    private EditText tv_neirong;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daka);
        findViewById(R.id.dakaa).setOnClickListener(this);
        findViewById(R.id.b_data).setOnClickListener(this);
        findViewById(R.id.b_start).setOnClickListener(this);
        findViewById(R.id.b_end).setOnClickListener(this);
        tv_data = findViewById(R.id.tv_data);
        tv_start = findViewById(R.id.tv_start);
        tv_end = findViewById(R.id.tv_end);
        tv_zhuti = findViewById(R.id.tv_zhuti);
        tv_neirong = findViewById(R.id.tv_neirong);
 
        findViewById(R.id.dakaa).setOnClickListener(this);
    }
 
    protected  void onStart(){
        super.onStart();
        mHelper = UserDBHelper.getInstance(this);
        mHelper.openReadLink();
        mHelper.openWriteLink();
    }
 
    protected void onStop(){
        super.onStop();
        mHelper.closeLink();
    }
 
    @Override
    public void onClick(View view) {
        Bean bean = null;
        switch (view.getId()){
            case R.id.b_data:
                int a,b,c;
                Calendar calendar = Calendar.getInstance();
                a=calendar.get(Calendar.YEAR);
                b=calendar.get(Calendar.MONTH);
                c=calendar.get(Calendar.DAY_OF_MONTH);
                DatePickerDialog dialog = new DatePickerDialog(this , this::onDataSet , a , b , c);
                dialog.show();
                break;
            case R.id.b_start:
                Calendar calendar1 = Calendar.getInstance();
                TimePickerDialog tdialog = new TimePickerDialog(this, this::onTimeSet,calendar1.get(Calendar.HOUR_OF_DAY),calendar1.get(Calendar.MINUTE),true);
                tdialog.show();
                break;
            case R.id.b_end:
                Calendar calendar2 = Calendar.getInstance();
                TimePickerDialog edialog = new TimePickerDialog(this, this::onTimeSet1,calendar2.get(Calendar.HOUR_OF_DAY),calendar2.get(Calendar.MINUTE),true);
                edialog.show();
                break;
            case R.id.dakaa:
                String Data = tv_data.getText().toString();
                String Zhuti = tv_zhuti.getText().toString();
                String Neirong = tv_neirong.getText().toString();
                String Stime = tv_start.getText().toString();
                String Etime = tv_end.getText().toString();
                bean = new Bean(Data,
                        Zhuti,
                        Neirong,
                        Stime,
                        Etime);
                if(mHelper.insert(bean)>0){
                    ToastUtil.show(this,"打卡成功");
                }
                break;
        }
    }
    public void onTimeSet(TimePicker view, int hourOfday, int minute){
        String desc =String.format("%d:%d",hourOfday,minute);
        tv_start.setText(desc);
    }
    public void onTimeSet1(TimePicker view, int hourOfday, int minute){
        String desc =String.format("%d:%d",hourOfday,minute);
        tv_end.setText(desc);
    }
    public void onDataSet (DatePicker view, int year,int month, int dayOfMonth) {
        String desc = String.format("%d年%d月%d日",year,month+1,dayOfMonth);
        tv_data.setText(desc);
    }
}

  

 

posted @   霍普金斯大学丁真  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示