我已使用Tabview
设置了Viewpager
3个标签。在第二个标签上,我设置了Recyclerview
。在Recyclerview项目onClick
之后我将从中删除该项目Recyclerview使用Recyclerview Aapter类并返回第一个选项卡。但是当我滚动到第二个选项卡时,看不到项目从Recyclerview中删除。我需要再次手动调用相同的tabview片段并反映更改。
这是从Recyclerview中删除项目的代码。
private void removeAtPosition(int adapterPosition) {
entry.remove(adapterPosition);
notifyItemRemoved(adapterPosition);
notifyItemRangeChanged(adapterPosition,entry.size());
}
这是删除项目后替换Tabview
的代码。
@Override
public void onClick(View v) {
//int position=getAdapterPosition();
BusyEntry values=this.entry.get(getAdapterPosition());
activity=(AppCompatActivity)v.getContext();
final AlertDialog alertDialog=new AlertDialog.Builder(activity).create();
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Confirmation");
builder.setMessage("Do you really want to Free the Entry?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
String NetworkStatus= biz.fyra.bookapp.utils.NetworkStatus.checkConnection(activity);
if(NetworkStatus.equals("false"))
{
AlertClass alert=new AlertClass();
alert.noInternetAlert(activity);
}
else
{
freeEntry();
String chooseTab="";
ChooseTab chooseTab1=new ChooseTab();
fm=activity.getSupportFragmentManager();
tx=fm.beginTransaction();
tx.replace(R.id.frame,chooseTab1,chooseTab);
removeAtPosition(getAdapterPosition());
BusyEntry entry=new BusyEntry();
tx.detach(entry);
tx.attach(entry);
tx.commit();
}
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
alertDialog.cancel();
}
});
builder.show();
}
}
如何处理此问题,以便立即从Recyclerview中删除已删除的项目,并在调用相同的片段后不可见。