|
3 | 3 | import android.os.Bundle;
|
4 | 4 | import android.support.v7.app.AppCompatActivity;
|
5 | 5 | import android.view.View;
|
| 6 | +import android.widget.TextView; |
6 | 7 |
|
7 | 8 | import com.hellohasan.eleventhclass.Database.DatabaseQuery;
|
8 | 9 | import com.hellohasan.eleventhclass.R;
|
9 | 10 | import com.orhanobut.logger.Logger;
|
10 | 11 |
|
11 | 12 | import java.util.List;
|
12 | 13 |
|
| 14 | +import butterknife.BindView; |
| 15 | +import butterknife.ButterKnife; |
| 16 | + |
13 | 17 | public class StudentCreateActivity extends AppCompatActivity {
|
14 | 18 |
|
| 19 | + @BindView(R.id.studentCountTextView) |
| 20 | + TextView studentCountTextView; |
| 21 | + |
| 22 | + private DatabaseQuery databaseQuery = new DatabaseQuery(this); |
| 23 | + |
15 | 24 | @Override
|
16 | 25 | protected void onCreate(Bundle savedInstanceState) {
|
17 | 26 | super.onCreate(savedInstanceState);
|
18 | 27 | setContentView(R.layout.activity_student_create);
|
| 28 | + ButterKnife.bind(this); |
19 | 29 |
|
20 |
| - |
| 30 | + //print number of students in db |
| 31 | + studentCountTextView.setText(String.valueOf(databaseQuery.getStudentCount())); |
21 | 32 | }
|
22 | 33 |
|
23 | 34 | public void addEntryToDatabase(View view) {
|
| 35 | + //every time we'll create student object with same data. and insert to database |
24 | 36 | Student student = new Student( "John", 123522, "01522235524", "[email protected]");
|
25 |
| - DatabaseQuery databaseQuery = new DatabaseQuery(this); |
26 |
| - databaseQuery.insertStudent(student); |
27 | 37 |
|
| 38 | + databaseQuery.insertStudent(student); //insert student object (actually data) into database |
| 39 | + |
| 40 | + //you'll find all students of db in studentList |
28 | 41 | List<Student> studentList = databaseQuery.getAllStudent();
|
29 |
| - Logger.d("List Length: " + studentList.size()); |
| 42 | + Logger.d("Number of Student: " + studentList.size()); //get student count |
| 43 | + //place a debugging breakpoint at this line or above line and check the studentList in debug monitor |
| 44 | + |
| 45 | + //another way to count students in db |
| 46 | + long count = databaseQuery.getStudentCount(); |
| 47 | + studentCountTextView.setText(String.valueOf(count)); //print the counter into TextView |
30 | 48 | }
|
31 | 49 | }
|
0 commit comments