Recycler View cannot refresh the cards

I am using recyclerview and cardview to display details but when i delete a particular row from sqlite it remains on the view i don't now where should i code to refresh the recyclerview after delete and also after deleting view if i tried to add new details i.e card it does not show up in the view.

And also i tried to implement radiobutton when i scroll it changes how to stop that.

I am new to Android and recyclerview so i am not aware where to implement codes such as notifyDataSetChanged() or invalidate() so can you guyz help me out with the above stated problem.

MyAdapter class

  public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {


static   List<EmployeeDetails> dbList;
static  Context context;
MyAdapter(Context context, List<EmployeeDetails> dbList ){
    this.dbList = new ArrayList<EmployeeDetails>();
    this.context = context;
    this.dbList = dbList;


}


@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
            R.layout.card_item, null);

    // create ViewHolder

    ViewHolder viewHolder = new ViewHolder(itemLayoutView);
    return viewHolder;


}

@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {

    holder.name.setText(dbList.get(position).getName1());
    holder.phone.setText(dbList.get(position).getPhone1());


}

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

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public TextView name,phone;
    public ImageView i,edit,delete;
   // public RadioButton p,a,l;


     DatabaseHelper helper=new DatabaseHelper(MyAdapter.context);


    public ViewHolder(View itemLayoutView) {
        super(itemLayoutView);


        i=(ImageView)itemLayoutView.findViewById(R.id.empimage);
        name = (TextView) itemLayoutView
                .findViewById(R.id.rvname);
        phone = (TextView)itemLayoutView.findViewById(R.id.rvphone);

        edit=(ImageView)itemLayoutView.findViewById(R.id.edit);
        delete=(ImageView)itemLayoutView.findViewById(R.id.delete);

       /* p=(RadioButton)itemLayoutView.findViewById(R.id.Present);
        a=(RadioButton)itemLayoutView.findViewById(R.id.Absent);
        l=(RadioButton)itemLayoutView.findViewById(R.id.Leave);
  */


        itemLayoutView.setOnClickListener(this);
        delete.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v)
                    {

                        String s=name.getText().toString();
                        EmployeeDetails e=new EmployeeDetails();

                        helper.deleteARow(s);



                    }
                }



        );


    }




    @Override
    public void onClick(View v) {

    }

class where Recyclerview is implemented

 public class Employees extends Fragment implements View.OnClickListener {
DatabaseHelper helpher;
List<EmployeeDetails> dbList;
RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;


public Employees() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.employees, container, false);

    FloatingActionButton fab= (FloatingActionButton) rootView.findViewById(R.id.fab);

    fab.setOnClickListener(this);




   //Recycle

    helpher=new DatabaseHelper(getActivity());

    dbList= new ArrayList<EmployeeDetails>();
    dbList = helpher.getDataFromDB();


    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_recycler_view);
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
   mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter
    mAdapter = new MyAdapter(getActivity(),dbList);
    mRecyclerView.setAdapter(mAdapter);
  //  mAdapter.notifyDataSetChanged();
   // mRecyclerView.invalidate();
    return rootView;

}



@Override
public void onClick(View view) {
    Intent intent=new Intent(getActivity(),addemployee.class);
    startActivity(intent);
}

Help me with this I searched a lot on internet but i cannot find a proper way

EDIT

my db code to retrieve data

           public List<EmployeeDetails> getDataFromDB(){
    List<EmployeeDetails> modelList = new ArrayList<EmployeeDetails>();
    String query = "select name,phone_no from "+TABLE_NAME1;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(query,null);

    if (cursor.moveToFirst()){
        do {
            EmployeeDetails model = new EmployeeDetails();
            model.setName1(cursor.getString(0));
            model.setPhone1(cursor.getString(1));
           // model.setRoll(cursor.getString(2));
            //model.setAddress(cursor.getString(3));
            //model.setBranch(cursor.getString(4));

            modelList.add(model);
        }while (cursor.moveToNext());
    }


ANSWERS:


Looks like you want to delete the row after clicking on delete image .

okay so call notifyItemRemoved(position); inside delete.setOnClickListene(.....).

and also make sure your delete action deletes the entry from dbList instance also else deleted row will be visible after refresh (when you rerun activity or scroll )

if your function helper.deleteARow(s); refreshes dbList then call notifyItemRemoved(position); just after helper.deleteARow(s); line inside delete.setOnClickListene(.....).

new code:

 delete.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v)
                {

                    String s=name.getText().toString();
                    EmployeeDetails e=new EmployeeDetails();

                    helper.deleteARow(s);

                   notifyItemRemoved(position);`

                }
            }



    );

you can call notifyDataSetChanged() also but it will refresh all row which is not necessary .



 MORE:


 ? Modifying Images resolution and size to fit card view properiries
 ? Error on Recycler view on fragment
 ? Count number automatically for card view
 ? Displaying two columns of a CardView in a LinearLayout
 ? Why does findViewById returns null for CardView?
 ? Android: using pictures in CardView + RecyclerView
 ? Persist corner radius of a CardView on setting background of a layout inside that CardView
 ? Android Cardview using recycleview with header and details
 ? Android Studio - Unable to use cardview with android API 25
 ? Android - Select card by name