Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Intent;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- 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 java.util.ArrayList;
- public class FilterStudents extends AppCompatActivity {
- EditText filter_uname, filter_fname, filter_lname, filter_major, filter_gpaLow, filter_gpaHigh;
- Button filter_filter, filter_back;
- ListView filter_listView;
- ArrayList<String> foundStudents;
- ArrayAdapter adapter;
- static ArrayList<Student> filterArrayList = new ArrayList<>();
- FilterBaseAdapter filterAdapter;
- static ArrayList<Student> filterStudentList = new ArrayList<>();
- DatabaseHelper dbHelper;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- EdgeToEdge.enable(this);
- setContentView(R.layout.activity_filter_students);
- filter_uname = findViewById(R.id.et_filter_u);
- filter_fname = findViewById(R.id.et_filter_f);
- filter_lname = findViewById(R.id.et_filter_l);
- filter_major = findViewById(R.id.et_filter_major);
- filter_gpaLow = findViewById(R.id.et_filter_gpaLow);
- filter_gpaHigh = findViewById(R.id.et_filter_gpaUpper);
- filter_filter = findViewById(R.id.btn_filter_filter);
- filter_back = findViewById(R.id.btn_filter_back);
- filter_listView = findViewById(R.id.lv_filter);
- filterAdapter = new FilterBaseAdapter(this, filterArrayList);
- filter_listView.setAdapter(filterAdapter);
- dbHelper = new DatabaseHelper(this);
- foundStudents = new ArrayList<String>();
- filterArrayList = new ArrayList<>();
- filterFilterListener();
- filterBackListener();
- }
- public void filterFilterListener() {
- filter_filter.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Log.d("Code called?", "YES");
- String uname = "";
- String fname = "";
- String lname = "";
- String major = "";
- //0 is lowest natural GPA and 6 is highest, so people shouldn't be searching for GPAs outside of this range anyway
- Float gpaLow = 0F;
- Float gpaHigh = 6F;
- //Grab data from edit text (DONE)
- //"!" means "is not"
- if (!filter_uname.getText().toString().isEmpty()){
- uname = filter_uname.getText().toString();
- }
- if (!filter_fname.getText().toString().isEmpty()) {
- fname = filter_fname.getText().toString();
- }
- if (!filter_lname.getText().toString().isEmpty()) {
- lname = filter_lname.getText().toString();
- }
- if (!filter_major.getText().toString().isEmpty()) {
- major = filter_major.getText().toString();
- }
- if (!filter_gpaLow.getText().toString().isEmpty()) {
- gpaLow = Float.parseFloat(filter_gpaLow.getText().toString());
- }
- if (!filter_gpaHigh.getText().toString().isEmpty()) {
- gpaHigh = Float.parseFloat(filter_gpaHigh.getText().toString());
- }
- Log.d("Strings assigned?", "YES");
- foundStudents = dbHelper.findStudentGivenCritera(uname, fname, lname, major, gpaLow, gpaHigh);
- for (int i = 0; i < foundStudents.size(); i++) {
- Log.d("uname: ", foundStudents.get(i));
- //filling the listview (NOT DONE)
- }
- }
- });
- }
- private void filterBackListener() {
- filter_back.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent filterToMain = new Intent(FilterStudents.this, MainActivity.class);
- startActivity(filterToMain);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement