Advertisement
Guest User

FilterStudents.java

a guest
Nov 3rd, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. import android.content.Intent;
  2. import android.database.Cursor;
  3. import android.os.Bundle;
  4. import android.util.Log;
  5. import android.view.View;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.ListView;
  10.  
  11. import androidx.activity.EdgeToEdge;
  12. import androidx.appcompat.app.AppCompatActivity;
  13. import androidx.core.graphics.Insets;
  14. import androidx.core.view.ViewCompat;
  15. import androidx.core.view.WindowInsetsCompat;
  16.  
  17. import java.util.ArrayList;
  18.  
  19. public class FilterStudents extends AppCompatActivity {
  20.  
  21. EditText filter_uname, filter_fname, filter_lname, filter_major, filter_gpaLow, filter_gpaHigh;
  22. Button filter_filter, filter_back;
  23. ListView filter_listView;
  24.  
  25. ArrayList<String> foundStudents;
  26. ArrayAdapter adapter;
  27. static ArrayList<Student> filterArrayList = new ArrayList<>();
  28. FilterBaseAdapter filterAdapter;
  29. static ArrayList<Student> filterStudentList = new ArrayList<>();
  30.  
  31. DatabaseHelper dbHelper;
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. EdgeToEdge.enable(this);
  36. setContentView(R.layout.activity_filter_students);
  37. filter_uname = findViewById(R.id.et_filter_u);
  38. filter_fname = findViewById(R.id.et_filter_f);
  39. filter_lname = findViewById(R.id.et_filter_l);
  40. filter_major = findViewById(R.id.et_filter_major);
  41. filter_gpaLow = findViewById(R.id.et_filter_gpaLow);
  42. filter_gpaHigh = findViewById(R.id.et_filter_gpaUpper);
  43. filter_filter = findViewById(R.id.btn_filter_filter);
  44. filter_back = findViewById(R.id.btn_filter_back);
  45.  
  46. filter_listView = findViewById(R.id.lv_filter);
  47.  
  48. filterAdapter = new FilterBaseAdapter(this, filterArrayList);
  49. filter_listView.setAdapter(filterAdapter);
  50.  
  51. dbHelper = new DatabaseHelper(this);
  52. foundStudents = new ArrayList<String>();
  53. filterArrayList = new ArrayList<>();
  54.  
  55. filterFilterListener();
  56. filterBackListener();
  57. }
  58.  
  59. public void filterFilterListener() {
  60. filter_filter.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View view) {
  63. Log.d("Code called?", "YES");
  64. String uname = "";
  65. String fname = "";
  66. String lname = "";
  67. String major = "";
  68. //0 is lowest natural GPA and 6 is highest, so people shouldn't be searching for GPAs outside of this range anyway
  69. Float gpaLow = 0F;
  70. Float gpaHigh = 6F;
  71.  
  72. //Grab data from edit text (DONE)
  73. //"!" means "is not"
  74. if (!filter_uname.getText().toString().isEmpty()){
  75. uname = filter_uname.getText().toString();
  76. }
  77. if (!filter_fname.getText().toString().isEmpty()) {
  78. fname = filter_fname.getText().toString();
  79. }
  80. if (!filter_lname.getText().toString().isEmpty()) {
  81. lname = filter_lname.getText().toString();
  82. }
  83. if (!filter_major.getText().toString().isEmpty()) {
  84. major = filter_major.getText().toString();
  85. }
  86. if (!filter_gpaLow.getText().toString().isEmpty()) {
  87. gpaLow = Float.parseFloat(filter_gpaLow.getText().toString());
  88. }
  89. if (!filter_gpaHigh.getText().toString().isEmpty()) {
  90. gpaHigh = Float.parseFloat(filter_gpaHigh.getText().toString());
  91. }
  92. Log.d("Strings assigned?", "YES");
  93.  
  94. foundStudents = dbHelper.findStudentGivenCritera(uname, fname, lname, major, gpaLow, gpaHigh);
  95.  
  96. for (int i = 0; i < foundStudents.size(); i++) {
  97. Log.d("uname: ", foundStudents.get(i));
  98. //filling the listview (NOT DONE)
  99. }
  100.  
  101. }
  102. });
  103. }
  104.  
  105. private void filterBackListener() {
  106. filter_back.setOnClickListener(new View.OnClickListener() {
  107. @Override
  108. public void onClick(View view) {
  109. Intent filterToMain = new Intent(FilterStudents.this, MainActivity.class);
  110. startActivity(filterToMain);
  111. }
  112. });
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement