2024/04/19(2024春季)

学习时长:2小时

代码行数:140行左右

博客数量:1篇

今天完成个人作业教师页面查看学生打卡总次数的功能部分

<?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"
    tools:context=".MainActivityEveryone"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:text="@string/id"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:layout_weight="9">
        </TextView>
        <Space
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <TextView
            android:text="@string/name"
            android:layout_width="0sp"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_weight="9">
        </TextView>
        <Space
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <TextView
            android:text="@string/username"
            android:layout_width="0sp"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_weight="9">
        </TextView>
        <Space
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <TextView
            android:text="@string/user_class"
            android:layout_width="0sp"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_weight="9">
        </TextView>

        <Space
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <TextView
            android:text="@string/total_num"
            android:layout_width="0sp"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_weight="9">
        </TextView>
    </LinearLayout>
    <ListView
        android:id="@+id/everyone_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>
package com.example.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

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

import com.example.myapplication.adapter.EveryOneAdapter;
import com.example.myapplication.pojo.EveryOne;
import com.example.myapplication.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MainActivityEveryone extends AppCompatActivity {

    private ListView every_list;
    private List<EveryOne> list;
    private EveryOneAdapter everyOneAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_everyone);
        init();
        new Thread(new Runnable() {
            @Override
            public void run() {
                Connection connection=null;
                connection= JDBCUtils.getConn();
                String sql="select name,user.username,classroom,count(record.username) from user left join record on user.username=record.username group by user.username";
                try {
                    PreparedStatement ps=connection.prepareStatement(sql);
                    ResultSet resultSet=ps.executeQuery();
                    Integer i=1;
                    while (resultSet.next())
                    {
                        EveryOne everyOne=new EveryOne();
                        everyOne.setId(i++);
                        everyOne.setName(resultSet.getString(1));
                        everyOne.setUsername(resultSet.getString(2));
                        everyOne.setClass_no(resultSet.getString(3));
                        everyOne.setTotal(resultSet.getInt(4));
                        list.add(everyOne);
                    }
                    MainActivityEveryone.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            everyOneAdapter=new EveryOneAdapter(list,MainActivityEveryone.this);
                            Log.e("dhajkda","dajkhladsa");
                            every_list.setAdapter(everyOneAdapter);
                        }
                    });
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }
    private void init()
    {
        every_list=findViewById(R.id.everyone_list);
        list=new ArrayList<>();
    }
}

 

 

posted @ 2024-04-19 22:06  伐木工熊大  阅读(4)  评论(0编辑  收藏  举报