冲刺第五天

 

昨天任务是完成多条件的查询

今天的任务依旧是完成多条件的查询

困难时如何将后端的值传入dao层

package com.example.tuandui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tuandui.dao.Jzdao;
import com.example.tuandui.entity.Jz;
import java.util.ArrayList;
import java.util.List;

public class Jzchaxun extends AppCompatActivity {

private EditText editDonator;
private EditText editLocation;
private EditText editClasses;
private Button buttonSearch;

private RecyclerView recyclerView;
private JzAdapter adapter;
private LinearLayoutManager layoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jzchaxun);

// 初始化控件
editDonator = findViewById(R.id.edit_donator);
editLocation = findViewById(R.id.edit_location);
editClasses = findViewById(R.id.edit_classes);
buttonSearch = findViewById(R.id.button_search);
recyclerView = findViewById(R.id.recyclerView);

// 设置RecyclerView
adapter = new JzAdapter(new ArrayList<>());
//当数据超出屏幕是可以滚动屏幕
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

// 搜索按钮点击事件
buttonSearch.setOnClickListener(v -> {
String donator = editDonator.getText().toString().trim();
String location = editLocation.getText().toString().trim();
String classes = editClasses.getText().toString().trim();


queryJz(donator, location, classes);
});
}

private void queryJz(String donator, String location, String classes) {
new Thread(() -> {
List<Jz> result = Jzdao.queryStudents(donator, location, classes);
runOnUiThread(() -> {
adapter.setData(result);
recyclerView.scrollToPosition(0);
});
}).start();
}
}
posted @ 2024-04-27 19:05  欧吼吼  阅读(4)  评论(0编辑  收藏  举报