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;


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;


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


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) {

        name = (TextView) itemLayoutView
        phone = (TextView)itemLayoutView.findViewById(;


       /* p=(RadioButton)itemLayoutView.findViewById(;

                new View.OnClickListener() {
                    public void onClick(View v)

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





    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() {


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

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

    FloatingActionButton fab= (FloatingActionButton) rootView.findViewById(;



    helpher=new DatabaseHelper(getActivity());

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

    mRecyclerView = (RecyclerView) rootView.findViewById(;

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

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


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

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


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.setRoll(cursor.getString(2));

        }while (cursor.moveToNext());


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:

            new View.OnClickListener() {
                public void onClick(View v)

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





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


 ? 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