public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment1_layout, container, false);
arrayList.clear();
arrayList2.clear();
dbHelper = new DatabaseHelper(getContext());
try {
dbHelper.checkAndCopyDatabase();
dbHelper.openDatabase();
} catch (SQLException e) {
}
try {
Cursor cursor = dbHelper.QueryData("select * from instructor");
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
Item item = new Item();
item.setId(cursor.getString(0));
item.setName(cursor.getString(1));
item.setCourse(cursor.getString(2));
item.setFavorite(cursor.getString(3));
arrayList.add(item);
if(cursor.getString(3).equals("true")){
arrayList2.add(item);
}
} while (cursor.moveToNext());
}
}
} catch (SQLException e) {
}
adapter = new Adapter(getActivity(), R.layout.custom_list_item, arrayList);
listView = (ListView) v.findViewById(R.id.listOfItems);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
return v;
}
이게 fragment1에 넣은 코드입니다. 제가 맨위에 arrayList.clear를 사용하지 않으면 tab2,
tab3으로 간다음에 tab1로 가면 다시 이 코드가 실행됩니다.
그래서 fragment1에 이미 database에 넣은 데이터가 다시 로드가 됩니다.
처음 한번만 이 코드가 실행되게끔 가능할까요?