#1프래그먼트에서 입력한 값을 어뎁터와 db를 이용해 #2프래그먼트에서 리싸이클러뷰에 조회하고 #3프래그먼트에서 얼마나 누적 입력횟수를 보여주려고 합니다.
TestAdapter adapter;
TextView korea_practicenumber_textVIew;
OnDatabaseCallback callback;
@Override
public void onAttach(Context context) {
super.onAttach(context);
callback = (OnDatabaseCallback) getActivity();
}
private HomeViewModel homeViewModel;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false);
korea_practicenumber_textVIew = root.findViewById(R.id.korea_practicenumber_textVIew);
adapter = new TestAdapter();
int countKor = adapter.getItemCount();
korea_practicenumber_textVIew.setText(countKor+ " 회");
return root;
}
여기 코드는 #3에 해당하는 프래그먼트입니다. korea_practicenumber_textView에 db를 이용해 적립된 리싸이클러뷰 아이템 개수를 setText하고 싶은데 계속해서 0값만 반환됩니다.
이 방법이 아니라면
db에서 cursor.getCount()를 해야할까요?
--이 코드는 db 코드중 조회하는 함수부분입니다--
public ArrayList<TestInfo> selectAll() {
ArrayList<TestInfo> result = new ArrayList<TestInfo>();
try {
Cursor cursor = db.rawQuery("select YEAR, MONTH, AGE, GRADE, SCORE from " + TABLE_TEST_INFO, null);
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
String year = cursor.getString(0);
String month = cursor.getString(1);
String age = cursor.getString(2);
String grade = cursor.getString(3);
String score = cursor.getString(4);
TestInfo info = new TestInfo(year, month, age, grade, score);
result.add(info);
}
int count_kor = cursor.getCount();
} catch(Exception ex) {
}
return result;
}
이런식으로 cursor.getCount()를 했다면 #3프래그먼트에서 이 정수값을 어떻게 반환받을까요?