10天冲刺第九天

今天做了什么:

通知界面:

<?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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".noticeActivity">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@color/white"/>
    <ScrollView android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        tools:ignore="MissingConstraints">
        <LinearLayout
            android:id="@+id/ll_notice"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:textSize="30dp"
                    android:gravity="center"
                    android:background="@drawable/shape_gray_square_bg"
                    android:text="用户名"/>
                <TextView
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:textSize="30dp"
                    android:text="联系方式"
                    android:background="@drawable/shape_gray_square_bg"
                    android:gravity="center"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="30dp"
                    android:text="日期"
                    android:background="@drawable/shape_gray_square_bg"
                    android:gravity="center"/>
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

</LinearLayout>

  资源文件:

<?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:background="@drawable/shape_gray_square_bg"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/tv_name"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:gravity="center"
            android:text="用户名"
            android:minLines="2"/>
        <TextView
            android:id="@+id/tv_method"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="联系方式"
            android:background="@drawable/shape_gray_square_bg"
            android:minLines="2"
            android:gravity="center"/>
        <TextView
            android:id="@+id/tv_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15dp"
            android:text="日期"
            android:gravity="center"
            android:minLines="2"/>
    </LinearLayout>

</LinearLayout>

  代码:

package com.example.psychological;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.psychological.javaClass.Dao;
import com.example.psychological.javaClass.Notice;

import java.sql.SQLException;

public class noticeActivity extends AppCompatActivity {

    private TextView tv_name;
    private TextView tv_method;
    private TextView tv_date;
    private LinearLayout ll_notice;
    private LinearLayout myLinear;
    private Notice[] notices=new Notice[100];
    private String[] name=new String[100];
    private Handler handler=new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message msg) {
            switch (msg.what){
                case 0:
                    int i=0;
                    while (notices[i].getUid()!=null){
                        myLinear = (LinearLayout) LayoutInflater.from(noticeActivity.this).inflate(R.layout.notice,null);
                        tv_name=myLinear.findViewById(R.id.tv_name);
                        tv_method=myLinear.findViewById(R.id.tv_method);
                        tv_date=myLinear.findViewById(R.id.tv_date);
                        tv_name.setText(name[i]);
                        tv_method.setText(notices[i].getMethod());
                        tv_date.setText(notices[i].getDate());
                        int finalI = i;
                        myLinear.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent=new Intent(noticeActivity.this, noti_user.class);
                                Bundle bundle = new Bundle();
                                bundle.putString("id",notices[finalI].getUid());
                                intent.putExtras(bundle);
                                startActivity(intent);
                            }
                        });
                        ll_notice.addView(myLinear);
                        i++;
                    }
                    break;
            }
            return true;
        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_notice);
        getSupportActionBar().hide();
        ll_notice = findViewById(R.id.ll_notice);
        initData();
    }

    public void initData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                SharedPreferences sharedPreferences=getSharedPreferences("user",MODE_PRIVATE);
                String id =sharedPreferences.getString("id","");
                Dao d =new Dao();
                try {
                    notices=d.allNotice(id);
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
                int i=0;
                while (notices[i].getUid()!=null){
                    try {
                        name[i]=d.checkName(notices[i].getUid());
                    } catch (SQLException e) {
                        throw new RuntimeException(e);
                    }
                    i++;
                }
                Message msg=new Message();
                msg.what=0;
                handler.sendMessage(msg);
            }
        }).start();
    }
}

  明天做什么:

每日记录功能

遇到的问题:界面跳转传参

posted @ 2024-04-28 19:14  umiQa  阅读(3)  评论(0编辑  收藏  举报