はよくあなたは、リスト、およびアダプターを持っている、とrecyclerview
ArrayList<String> myQuoteList = new ArrayList<String>();
MyCustomAdapter adapter = new MyCustomAdapter(myQuoteList);
rcvQuotes.setAdapter(adapter);
は、その後、あなたの削除にあなただけのインターフェイスを作る//
private void deleteAtIndex(int index){
myQuoteList.remove(index);
adapter.notifyDataSetChanged();
}
を行うことができます。
public interface fragmentCallback{
boolean onQuoteDeleted(Quote deleteQuote);
}
は、あなたの活動を持っているインターフェイスを実装:
myActivity implements fragmentCallback{
public boolean onQuoteDeleted(Quote deletedQuote){
if(myQuotelist.contains(deleteQuote){
myQuoteList.remove(deleteQuote);
adapter.notifyDataSetChanged();
}
}
}
その後、フラグメントに
myFragment.setQuote(selectedQuote);
simpleyフラグメントの内側だけで操作を行います。
@Override
public void onAttach(Context context) {
super.onAttach(context);
try{
mFragmentCallback = (IFragmentCallback) context;
}catch (Exception ex){
A35Log.e(TAG, "Parent Context does not implement fragmentCallback");
}
}
public void setQuote(Quote showQuote){
mSelectedQuote = showQuote;
}
btnDelete_onClick(){
if(mFragmentCallback != null){
mFragmentCallback.onDeleteQuote(mSelectedQuote);
}
}
あなたがでそれを処理することができます選択されたtのインデックスまたは最後の索引や最初の索引を使用して、行項目に長いタッチ・リスナーまたはごみ箱を追加することができます。どのようにインデックスを取得するかはあなた次第です。
それだけです、それはすべてです。
出典
2017-09-29 18:36:33
Sam
データの表示にシリアライザを使用していますか?私は解決策を与えることができるようにここでコードを共有する必要があります。ペーストビンを行う。 –
[RecyclerView-Androidのアイテムを削除する](https://stackoverflow.com/questions/36858086/remove-an-item-in-recyclerview-android) – HEATH3N
@BilalShahid私はそれにQuoteというシリアライザを使用しています。おかげで – Priya