简单记事本app4

——新增便签——

activity_note_add.xml  界面设计

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:background="@color/yellow"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="OvO"
android:textColor="@color/orange"
android:textSize="35sp"
android:gravity="center"
android:layout_marginTop="100dp"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="70dp">
<EditText
android:id="@+id/an_et_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16sp"
android:textColor="@color/black"
android:hint=" 标题"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/an_et_keywords"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 关键字"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/an_et_contents"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 内容"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
</LinearLayout>

<Button
android:id="@+id/an_addnote_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="添加事件"
android:textColor="@color/black"
android:background="@drawable/bg_frame"
android:layout_marginLeft="2dp"
android:layout_marginTop="50dp"
/>

</LinearLayout>

Note Add Activity.Java

package com.example.text002;

import static db.DBManager.insertNote;

import androidx.appcompat.app.AppCompatActivity;

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

public class NoteAddActivity extends AppCompatActivity implements View.OnClickListener {

private Button an_addnote_btn;
private EditText an_et_title, an_et_keywords, an_et_contents, an_et_daytime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_add);
initfun();
}

private void initfun() {
an_et_title = findViewById(R.id.an_et_title);
an_et_keywords = findViewById(R.id.an_et_keywords);
an_et_contents = findViewById(R.id.an_et_contents);
//an_et_daytime = findViewById(R.id.an_et_daytime);

an_addnote_btn = findViewById(R.id.an_addnote_btn);
an_addnote_btn.setOnClickListener(NoteAddActivity.this);
}

@Override
public void onClick(View view) {
int vid = view.getId();
if(vid == R.id.an_addnote_btn){
//注册
String unan_et_title = an_et_title.getText().toString();
String unan_et_keywords = an_et_keywords.getText().toString();
String unan_et_contents = an_et_contents.getText().toString();
//String unan_et_daytime = an_et_daytime.getText().toString();
//title,keywords,contents,daytime
unan_et_title = isnull(unan_et_title);
unan_et_contents = isnull(unan_et_contents);
//unan_et_daytime = isnull(unan_et_daytime);
Boolean flag = insertNote(unan_et_title, unan_et_keywords, unan_et_contents);//, unan_et_daytime);
if(flag){
Toast.makeText(this,"事件添加成功OvO",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(NoteAddActivity.this,FunctionActivity.class);
startActivity(intent);
} else {
Toast.makeText(this,"事件添加失败TAT",Toast.LENGTH_SHORT).show();
}
}
}

private String isnull(String str) {
if(str.length() == 0 || str == null){
str = " ";
}
return str;
}
}
posted @   椰子灰  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示