RecyclerView
を次のように使用して、SQLite DBに更新されたプレイスアイテムのリストを表示しています。Android:RecyclerViewの最後のアイテムを削除する問題
アイテムは細かく削除され、スワイプすると更新されます。 最後のアイテムを削除するためにスワイプすると、ビューに戻ります。私は、アプリケーションを閉じて、アプリを再び開くと、アイテムが削除されます。
ただし、アイテムをスワイプして削除すると、そのアプリの実行中に複数回スワイプしても表示されなくなります。
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
int swipedPosition = viewHolder.getAdapterPosition();
PlaceListAdapter adapter = (PlaceListAdapter) mRecyclerView.getAdapter();
int pos = viewHolder.getAdapterPosition();
// Build appropriate uri with String row id appended
String stringId = places.get(pos).getId();
Log.d("testhro", stringId);
Uri uri = PlaceContract.PlaceEntry.CONTENT_URI;
uri = uri.buildUpon().appendPath(stringId).build();
Log.d("testhhd", uri.toString());
// COMPLETED (2) Delete a single row of data using a ContentResolver
getContentResolver().delete(uri, null, null);
mAdapter.notifyDataSetChanged();
refreshPlacesData();
}
refreshPlacesData()
private void refreshPlacesData() {
Uri uri = PlaceContract.PlaceEntry.CONTENT_URI;
Cursor data = getContentResolver().query(
uri,
null,
null,
null,
null);
if (data == null || data.getCount() == 0) return;
Log.d("countIs", String.valueOf(data.getCount()));
List<String> guids = new ArrayList<String>();
while (data.moveToNext()) {
guids.add(data.getString(data.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PLACE_ID)));
}
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mClient,
guids.toArray(new String[guids.size()]));
placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(@NonNull PlaceBuffer places) {
mAdapter.swapPlaces(places);
MainActivity.this.places = places;
mGeofencing.updateGeofencesList(places);
if (mIsEnabled) mGeofencing.registerAllGeofences();
}
});
}
私は何かが足りないのですか?ありがとう。
EDIT: 私が代わりにmAdapterのアダプタを更新しようとしたが、まだ何の変化
EDIT 2
public void swapPlaces(PlaceBuffer newPlaces) {
mPlaces = newPlaces;
if (mPlaces != null) {
// Force the RecyclerView to refresh
this.notifyDataSetChanged();
}
}
注:私もロガーを検証:
D /しませんcountIsZero:true(refreshPlacesData()内)
は、アダプタが、無ヘルプを更新してみました:/ – user3820753
[OK]を私はそれが – user3820753
を試してみましょう私がここでnotifyDataSetChanged()を使用しなくても、同じ方法で動作します – Rahul