1
1
package com .example .nobulijava .activity ;
2
2
3
+ import androidx .annotation .NonNull ;
3
4
import androidx .appcompat .app .AppCompatActivity ;
4
5
import androidx .recyclerview .widget .RecyclerView ;
5
6
10
11
import com .example .nobulijava .R ;
11
12
import com .example .nobulijava .adapters .QuizAdapter ;
12
13
import com .example .nobulijava .model .QuizObj ;
14
+ import com .google .android .gms .tasks .OnCompleteListener ;
15
+ import com .google .android .gms .tasks .Task ;
13
16
import com .google .android .material .floatingactionbutton .FloatingActionButton ;
14
17
import com .google .firebase .database .DataSnapshot ;
15
18
import com .google .firebase .database .DatabaseError ;
@@ -27,6 +30,8 @@ public class AdminQuizListActivity extends AppCompatActivity {
27
30
private DatabaseReference mDatabase ;
28
31
29
32
private ArrayList <QuizObj > quizObjArrayList ;
33
+ QuizAdapter quizAdapter ;
34
+
30
35
@ Override
31
36
protected void onCreate (Bundle savedInstanceState ) {
32
37
super .onCreate (savedInstanceState );
@@ -45,34 +50,26 @@ public void onClick(View v) {
45
50
startActivity (new Intent (AdminQuizListActivity .this , AdminQuizAddActivity .class ));
46
51
}
47
52
});
53
+
54
+ quizObjArrayList = new ArrayList <>();
55
+ quizAdapter = new QuizAdapter (quizObjArrayList , AdminQuizListActivity .this );
56
+ recyclerViewQuizList .setAdapter (quizAdapter );
57
+
48
58
mDatabase .child ("Quiz" ).addValueEventListener (new ValueEventListener () {
49
59
@ Override
50
60
public void onDataChange (DataSnapshot dataSnapshot ) {
51
- quizObjArrayList = new ArrayList <> ();
52
- for (DataSnapshot quizSnapshot : dataSnapshot .getChildren ()) {
61
+ quizObjArrayList . clear ();
62
+ for (DataSnapshot quizSnapshot : dataSnapshot .getChildren ()) {
53
63
QuizObj quizObj = quizSnapshot .getValue (QuizObj .class );
54
64
quizObj .setQuizID (quizSnapshot .getKey ());
55
65
quizObjArrayList .add (quizObj );
56
-
57
66
}
58
- QuizAdapter quizAdapter = new QuizAdapter (quizObjArrayList , AdminQuizListActivity .this );
59
- recyclerViewQuizList .setAdapter (quizAdapter );
60
- //TODO when delete item, recyclerview scrolls back to top
67
+ quizAdapter .notifyDataSetChanged ();
61
68
}
62
69
63
70
@ Override
64
71
public void onCancelled (DatabaseError databaseError ) {
65
72
}
66
73
});
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
74
}
76
-
77
-
78
75
}
0 commit comments