У меня есть RecyclerView
, и я могу добавить элементы из другой деятельности, когда элемент добавляется в SQLite DB
он возвращает меня к StartActivity, где я есть мой фрагмент с RecyclerView
который загрузится мой List<Items>
из SQLite DB
, но Fragment техника его подводит обновление, оно обновляется только тогда, когда я начала другой вид деятельностиКак обновить RecyclerView
Фрагмент:
public class MyCardsFragment extends Fragment {
public DataBaseAdapter data;
private static final String TAG = "MyApp";
private RecyclerView recyclerView;
DataBaseAdapter dataBaseHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my_cards, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recycleView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setItemAnimator(new DefaultItemAnimator());
dataBaseHelper = new DataBaseAdapter(getActivity());
recyclerView.setAdapter(new RecycleViewAdapter(dataBaseHelper.getData(),R.layout.custom_row));
recyclerView.getAdapter().notifyDataSetChanged();
return view;
}
}
Эта линия: recyclerView.getAdapter().notifyDataSetChanged();
д idnt work Как я могу быстро обновить свой recyclerView?
Edit:
DataBaseAdaptergetData
:
........
public List<Cards> getData(){
//рабочий лист
List<Cards> list = new ArrayList<>();
SQLiteDatabase sqLiteDatabase= helper.getWritableDatabase();
Cursor cursor= sqLiteDatabase.rawQuery(helper.QUERY,null);
while (cursor.moveToNext()){
int index0=cursor.getColumnIndex(helper.UID);
int index1=cursor.getColumnIndex(helper.KEY_NAME);
int index2=cursor.getColumnIndex(helper.KEY_VALUE);
int index3=cursor.getColumnIndex(helper.KEY_FORMAT);
int index4=cursor.getColumnIndex(helper.KEY_COUNTRY);
int index5=cursor.getColumnIndex(helper.KEY_CARD_HOLDER_NAME);
int index6=cursor.getColumnIndex(helper.KEY_CARD_RATING);
int index7=cursor.getColumnIndex(helper.KEY_VOTES_COUNT);
int index8=cursor.getColumnIndex(helper.KEY_RATED);
int index9=cursor.getColumnIndex(helper.KEY_CARD_IN_BASE_ID);
int index11=cursor.getColumnIndex(helper.KEY_CARD_DELETED_OR_NOT);
int cid = cursor.getInt(index0);
String name = cursor.getString(index1);
String value = cursor.getString(index2);
String format = cursor.getString(index3);
String country = cursor.getString(index4);
String holderName = cursor.getString(index5);
String cardRating = cursor.getString(index6);
String votesCount = cursor.getString(index7);
String rated = cursor.getString(index8);
String cardIdInBase = cursor.getString(index9);
String deletedOrNot = cursor.getString(index11);
Cards cards = new Cards(cid,name,format,value,country,holderName,cardRating,cardIdInBase,votesCount,rated,deletedOrNot);
list.add(cards);
}
return list;
}
......
Вы можете поделиться своим кодом getdata(), и сколько записей оно извлекает? – Fahim
@Fahim i have Редактировать свой вопрос – Ololoking
@Fahim мой английский теперь настолько хорош, что я не понял, что у вас значит в вашем вопросе – Ololoking