0

i have an Activity which has two tabs. Each tab has a RecyclerView and each RecyclerView has a specific Adapter. there is a button in each dataset of first tabs RecyclerView that deletes dataset in position and adds it to the next tab. My problem is that I should exit from Activityand enter again to see the added data in second tab. how can I update second tab immediately ?

 public class QCRepairAdapter extends RecyclerView.Adapter<QCRepairAdapter.MyViewHolder> {

    private LayoutInflater inflater;
    List<QCInfo> data = Collections.emptyList();

    public QCRepairAdapter(Context context, List<QCInfo> data) {

        inflater = LayoutInflater.from(context);
        this.data = data;

    }

    @Override
    public QCRepairAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.cards_qc_repair, parent, false);

        MyViewHolder holder = new MyViewHolder(view);

        return holder;

    }

    public void Delete(int position) {
        data.remove(position);
        notifyItemRemoved(position);
    }

    @Override
    public void onBindViewHolder(final QCRepairAdapter.MyViewHolder holder, final int position) {

        QCInfo current = data.get(position);
        holder.projectName.setText(current.projectName);
        holder.code.setText(current.code);
        holder.operator.setText(current.operatorName);

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        TextView projectName;
        TextView code;
        TextView operator;
        ImageView btn_accept;

        public MyViewHolder(final View itemView) {
            super(itemView);
            projectName = (TextView) itemView.findViewById(R.id.tv_card_qc_repair_name);
            code = (TextView) itemView.findViewById(R.id.tv_card_qc_repair_code);
            operator = (TextView) itemView.findViewById(R.id.tv_card_qc_repair_operatorName);
            btn_accept = (ImageView) itemView.findViewById(R.id.iv_card_qc_repair_accept);
            btn_accept.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {

                showDialog(v.getContext(), "تایید فرآیند ؟", "qcAccept", code.getText().toString(), getPosition());

        }
    }

    private void showDialog(final Context context, String message, final String method, final String code, final int position) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("هشدار")
                .setIcon(R.drawable.alert)
                .setMessage(message)
                .setPositiveButton("بله", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        BackgroundTask backgroundTask = new BackgroundTask(context);
                        backgroundTask.execute(method, code);
                        Delete(position);
                    }
                })
                .setNegativeButton("خیر", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                .create().show();
    }
}
musica
  • 1,145
  • 2
  • 10
  • 29

0 Answers0