我已经在android上设计了一个产品购物车,列出了10个产品。在此,我要删除第7个产品,然后在相同位置重新加载产品购物车片段。请为此提供帮助。
holder.removeCartBtn.setOnClickListener(new View.OnClickListener(){//从购物车中删除产品 @Override public void onClick(最终视图){
String productId = productData.get_id();
ApiService api = ApiClient.getClient().create(ApiService.class);
Call <Response> call= api.removeCart(productId);
call.enqueue(new retrofit2.Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
Response jsonResponse = response.body();
String result = jsonResponse.getStatus();
if (result.equals("remove")){
Toast.makeText(mCtx, "Item Removed From Cart", Toast.LENGTH_SHORT).show();
notifyItemRemoved(position);
ViewCartFragment viewCartFragment = new ViewCartFragment();
AppCompatActivity activity = (AppCompatActivity)view.getContext();
activity.getSupportFragmentManager().beginTransaction().
replace(R.id.fragment_container,viewCartFragment).commit();
} else {
Toast.makeText(mCtx, "Item Not Removed From Cart",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Response> call, Throwable t) {
Toast.makeText(mCtx, "No Internet connection found. Check your connection " +
"or try again", Toast.LENGTH_LONG).show();
}
});
}
});
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataSet.size());