我正在尝试从RecyclerView删除项目动画正在发生但该项目未被清除。在我执行以下操作后,我得到了相同的项目:
notifyItemRemoved(favlistTransID);
notifyItemRangeChanged(favlistTransID, 1);
以下是我要做的事情:
当我点击它时,我有了recyclebin图标图标我调用了一个API来删除云服务器上的require项目并从RecyclerView清除它。
内部:扩展的适配器:RecyclerView.Adapter<FavouriteList_Adapter_Recycler.WishListViewHolder>
我有以下代码:
@Override
public void onBindViewHolder(WishListViewHolder personViewHolder, int i)
{
contactNameText = favlistDetails.get(i).getname().toString();
tempURL = favlistDetails.get(i).getImage().toString();
favlistTransID = favlistDetails.get(i).getfavtransID().toString();
mContext = personViewHolder.image.getContext();
TAG_MESSAGE = mContext.getResources().getString(R.string.tagmessage);
favDB = new favContactsDB(mContext);
customerID = favDB.getCustID();
if (tempURL.equalsIgnoreCase(""))
{
Picasso.with(mContext).load(url).placeholder(R.drawable.none).error(R.drawable.none).centerCrop().resize(218, 230).into(personViewHolder.image);
}
else
{
Picasso.with(mContext).load(favlistDetails.get(i).getImage().toString()).placeholder(R.drawable.none).error(R.drawable.none).centerCrop().resize(218, 230).into(personViewHolder.image);
}
personViewHolder.removeFav.setTag(i);
personViewHolder.removeFav.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Integer taggedPosition = (Integer) v.getTag();
Log.e("Position::-", Integer.toString(taggedPosition));
removeWish(taggedPosition);
}
});
}
//从API中删除并从列表中删除项目:
private void removeWish(final int wishlistTransID)
{
final RequestParams requestParams = new RequestParams();
requestParams.put("tokenValue", mContext.getResources().getString(R.string.tokenvalue));
requestParams.put("FavTranID", favlistDetails.get(favlistTransID).getfavtransID().toString());
requestParams.put("ContactID", customerID);
final String uploadWebsite = mContext.getResources().getString(R.string.removefavitem);
AsyncHttpClient client = new AsyncHttpClient();
client.post(uploadWebsite, requestParams, new JsonHttpResponseHandler()
{
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response)
{
try
{
success = response.getString(TAG_MESSAGE);
if (success.equalsIgnoreCase(mContext.getResources().getString(R.string.message)))
{ favDB.deletefavouritedetails(favlistDetails.get(favlistTransID).getname().toString());
Toast.makeText(mContext, mContext.getResources().getString(R.string.removefav), Toast.LENGTH_SHORT).show();
notifyItemRemoved(favlistTransID);
notifyItemRangeChanged(favlistTransID, 1);
}
else
{
Toast.makeText(mContext, mContext.getResources().getString(R.string.errorwish), Toast.LENGTH_SHORT).show();
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse)
{
super.onFailure(statusCode, headers, throwable, errorResponse);
Toast.makeText(mContext, mContext.getResources().getString(R.string.error_server), Toast.LENGTH_SHORT).show();
}
});
}
不确定是什么问题?
有人可以帮我解决过去两天一直在挣扎吗?
谢谢!
答案 0 :(得分:3)
您没有从数据源中删除该项,您必须从favlistDetails中删除该项,然后调用notifyItemRemoved();
onSuccess方法中的从DataSource中删除该项
<style name="AppTheme" parent="@style/Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>