——登录之后——
activity_function.xml List View实现滚动浏览,不过这一部分还没做完,目前浏览操作还没有连接上数据库
<?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="5dp"
android:background="@color/yellow"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="OvO"
android:textColor="@color/orange"
android:textSize="30sp"/>
<Button
android:id="@+id/add_note_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="30sp"
android:textColor="@color/orange"
android:background="@drawable/bg_frame"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
/>
</LinearLayout>
<ListView
android:id="@+id/lv_note"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="3dp"
android:scrollbars="none"
/>
</LinearLayout>
FunctionActivity.java
package com.example.text002;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import db.NoteAdapter;
import db.NoteBean;
public class FunctionActivity extends AppCompatActivity implements View.OnClickListener {
private Button add_note_btn;
private List<NoteBean> notes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_function);
initaddnote();
initView();
}
private void initaddnote() {
add_note_btn = findViewById(R.id.add_note_btn);
add_note_btn.setOnClickListener(FunctionActivity.this);
}
private void initView() {
ListView listView = findViewById(R.id.lv_note);
initData();
//适配器,让数据和listView结合起来,起到桥梁的作用
NoteAdapter noteAdapter = new NoteAdapter(FunctionActivity.this,notes);
listView.setAdapter(noteAdapter);
}
private void initData() {
notes = new ArrayList<>();
NoteBean note = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note);
NoteBean note1 = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note1);
NoteBean note2 = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note2);
NoteBean note3 = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note3);
NoteBean note4 = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note4);
NoteBean note5 = new NoteBean(" ", "学习", "学习打卡", "2023/3/18");
notes.add(note5);
}
@Override
public void onClick(View view) {
int vid = view.getId();
switch (vid){
case R.id.add_note_btn:
//添加新的note
// Toast.makeText(this,"HELLO~",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FunctionActivity.this,NoteAddActivity.class);
startActivity(intent);
break;
}
}
}
下一篇写实现新增便签
标签:layout,app3,add,note,NoteBean,简单,import,android,记事本 From: https://www.cnblogs.com/yansans/p/17232206.html