——新增便签——
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;标签:layout,title,app4,简单,et,android,unan,id,记事本 From: https://www.cnblogs.com/yansans/p/17232214.html
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;
}
}