问:
How to check if record exist in sqlite, if yes, then update it.?
first of all i'm describing some explanation about my question,
i have two fragments name as "Main Fragment" and second one is " Cart Fragment"

1==> Main Fragment- Contains recyclerview in which data comes from firestore and set in recyclerview, when user click on add or remove button then data is entered and update in sqlite.

2==> Cart Fragment- Contains recyclerview in which data comes from SQLITE and set in recycelerview.

My Question is when i navigate from cart fragment to Main Fragment then First check that any item is already saved in sqlite or not, if exist then get total item quantity from cart fragment of that item(including other data like name, price etc.) and set in main fragmnet.

Here code for Main Fragment Adapter

```<code>@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.TV_OFF.setText(_mylistdata.get(position).getDiscount()+"% OFF");
   //"Rs "+
    holder.TV_CURNT_PRICE.setText(_mylistdata.get(position).getCurr_price());
    holder.TV_OLD_PRICE.setText(_mylistdata.get(position).getOld_price());
    holder.TV_NAME.setText(_mylistdata.get(position).getName());
    holder.TV_OFFER_DES.setText(_mylistdata.get(position).getOffers_des());
    holder.TV_UNIT.setText(_mylistdata.get(position).getUnit_products()+" Unit");
    Picasso.get().load(_mylistdata.get(position).getImgId()).placeholder(R.drawable.no_image_find).into(holder.imageView);

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

            //Toast.makeText(context, "pos="+prd_id, Toast.LENGTH_SHORT).show();
            holder.add_btn.setVisibility(View.GONE);
            holder.TV_REMOVEITEM.setVisibility(View.VISIBLE);
            holder.TV_TOTALITEM.setVisibility(View.VISIBLE);
            holder.TV_ADDITEM.setVisibility(View.VISIBLE);
            count_value=1;

            holder.TV_TOTALITEM.setText(Integer.toString(count_value));
            // get data from views
            getDataFromViews(position);
            total_qty_pro= (String) holder.TV_TOTALITEM.getText();
            //qty_pro=_mylistdata.get(position).getUnit_products();
            qty_new=qty_pro+" Unit";
            saveData_To_SQLITE(new_name,qty_new,price_pro,price_old,total_qty_pro,image_id,context);

        }

    });
    holder.TV_REMOVEITEM.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {

            //productId= (int) getItemId(position);
            count_value--;
            if (count_value<1)
            {
                Log.d(TAG,"Remove button is pressed");
                holder.add_btn.setVisibility(View.VISIBLE);
                holder.TV_REMOVEITEM.setVisibility(View.GONE);
                holder.TV_TOTALITEM.setVisibility(View.GONE);
                holder.TV_ADDITEM.setVisibility(View.GONE);
                count_value=1;

                String prdct_name= _mylistdata.get(position).getName();

                delete_record(prdct_name,context);

            }else {
                //Data_parsing.setCountText(count_value);
                holder.TV_TOTALITEM.setText(Integer.toString(count_value));

                total_qty_pro= (String) holder.TV_TOTALITEM.getText();
                String prdct_name= _mylistdata.get(position).getName();

                UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

            }

        }
    });
    holder.TV_ADDITEM.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG,"Add button is pressed");
            count_value++;
            //Data_parsing.setCountText(count_value);
            holder.TV_TOTALITEM.setText(Integer.toString(count_value));

            total_qty_pro= (String) holder.TV_TOTALITEM.getText();
            String prdct_name= _mylistdata.get(position).getName();
            UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);
        }

    });
}
</code>```

Here is my SQLite class in which i define my static methods for saving, updating and delete my data from sqlite

public class SQLITE_RUD {

```<code>// Save data to sqlite
public static void  saveData_To_SQLITE(String name_pro, String qty_pro, String price_pro,String price_old, String total_qty_pro, String image_id, Context context) {
    DBAdapter db = new DBAdapter(context);
    db.openDB();
    long result =  db.add(name_pro, qty_pro, price_pro,price_old, total_qty_pro, image_id);
    if (result > 0) {
        Toast.makeText(context, "Data is saved succeffuly", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(context, "Unable to save", Toast.LENGTH_SHORT).show();
    }
    db.closeDB();
}

// update data in sqlite

public static void UPDATE_SQL_DATA(String p_name, String total_qty_pro, Context context)
{
    DBAdapter db=new DBAdapter(context);
    db.openDB();
    try {
        long result=db.update_DB(p_name,total_qty_pro);
        if(result>0)
        {
            Toast.makeText(context, "Updated Sucesfully", Toast.LENGTH_SHORT).show();
        }else
        {
            Toast.makeText(context, "Unable to update", Toast.LENGTH_SHORT).show();
        }
    }catch (Exception e)
    {
        Log.d("MyListAdapter","error_update="+e);
    }
    db.closeDB();
}
// Delete data from SQlite
public static void delete_record(String prdct_name,Context context) {
    //
    DBAdapter db=new DBAdapter(context);
    db.openDB();
    try {
        long result=db.Delete_DB(prdct_name);
        if(result>0)
        {
            Toast.makeText(context, "Deleted Sucesfully", Toast.LENGTH_SHORT).show();
        }else
        {
            Toast.makeText(context, "Unable to Delete", Toast.LENGTH_SHORT).show();
        }
    }catch (Exception e)
    {
        Log.d("MyListAdapter","error_delete="+e);
    }
    db.closeDB();
}
</code>```

}

Here i create class name ad DBAdapter in which i define methods for saving, updating, and retriving quires.

```<code>public class DBAdapter {
Context c;
SQLiteDatabase db;
DbHelper database_helper;   // on create and on upgrade is defined

public DBAdapter(Context c) {
    this.c = c;
    database_helper=new DbHelper(c);

}

//OPEN DB
public void openDB()
{
    try {
        db=database_helper.getWritableDatabase();
        db=database_helper.getReadableDatabase();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
//CLOSE DB
public void closeDB()
{
    try {
        database_helper.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

//INSERT/SAVE
public long add(String P_name,String P_qty,String P_price,String P_OldPrice,String P_Total_qty, String P_Image)
{
    try {
        ContentValues cv=new ContentValues();
        // cv.put(KEY_ItemID, P_id);
        cv.put(KEY_ProductName, P_name);
        cv.put(KEY_ProductQuantity, P_qty);
        cv.put(KEY_ProductPrice, P_price);
        cv.put(KEY_OldPrice, P_OldPrice);
        cv.put(KEY_ProductTotal, P_Total_qty);
        cv.put(KEY_ProductImage,P_Image);
        return db.insert(Table_name, KEY_RowID, cv);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
public long update_DB(String name_prdct, String prdct_TOTAL_QTY)
{
    try
    {
        ContentValues cv=new ContentValues();
        cv.put(KEY_ProductTotal,prdct_TOTAL_QTY);
        return db.update(Table_name,cv,KEY_ProductName +" =?",new String[]{String.valueOf(name_prdct)});
        //return;
    }catch (SQLException e)
    {
        e.printStackTrace();
    }

    return 0;
}

//DELETE
public long Delete_DB(String prdct_name)
{
    try
    {
        return db.delete(Table_name,KEY_ProductName+" =?",new String[]{String.valueOf(prdct_name)});

    }catch (SQLException e)
    {
        e.printStackTrace();
    }

    return 0;
}

//SELECT/RETRIEVE
public Cursor retrieve() {
    String[] columns = {KEY_RowID,KEY_ProductName,KEY_ProductQuantity, KEY_ProductPrice,KEY_OldPrice, KEY_ProductTotal, KEY_ProductImage};
    return db.query(Constants.Table_name, columns, null, null, null, null, null);
}
</code>```

}

Here is my Cart Fragment

```<code>public class CartFragment extends Fragment {
private static final String Tag ="CartFragment" ;
FragmentManager fragmentManager;
RecyclerView recyclerView;
RelativeLayout proceedBtn;
TextView finalprice_bottom, finalprice_upper;
Adapter_chart adapter;
View view;
ArrayList<Chart_getter_setter> chartGetterSetters = new ArrayList<>();

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                         final Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view= inflater.inflate(R.layout.fragment_cart, container, false);
    recyclerView = view.findViewById(R.id.chart_recyclerview);
    proceedBtn=view.findViewById(R.id.bottomChart);

    finalprice_upper=view.findViewById(R.id.price);
    finalprice_bottom =view.findViewById(R.id.FinalPrice_TV);
    proceedBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(savedInstanceState==null) {
                getFragmentManager().beginTransaction().replace(R.id.fragment_container, ProceedFragment.newInstance()).addToBackStack(null).commit();
            }
        }
    });

    adapter = new Adapter_chart(getActivity(), fragmentManager, chartGetterSetters);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayout.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);

    //RETRIEVE
    retrieve_data();

    getActivity().setTitle("Final chart");

    return view;
}
private void retrieve_data() {
    DBAdapter db = new DBAdapter(getContext());
    db.openDB();
    chartGetterSetters.clear();
    //RETRIEVE
    Cursor c = db.retrieve();
    while (c.moveToNext())
    {
        int index_id=c.getColumnIndex(Constants.KEY_RowID);
        int index_name=c.getColumnIndex(Constants.KEY_ProductName);
        int index_qty=c.getColumnIndex(Constants.KEY_ProductQuantity);
        int index_price=c.getColumnIndex(Constants.KEY_ProductPrice);
        int index_oldprice=c.getColumnIndex(Constants.KEY_OldPrice);
        int index_total=c.getColumnIndex(Constants.KEY_ProductTotal);
        int index_image=c.getColumnIndex(Constants.KEY_ProductImage);

        int id=c.getInt(index_id);
        String name=c.getString(index_name);
        String qty=c.getString(index_qty);
        String price=c.getString(index_price);
        String oldPrice=c.getString(index_oldprice);
        String total=c.getString(index_total);
        String IMAGE=c.getString(index_image);

        Chart_getter_setter p=new Chart_getter_setter(name,qty,price,oldPrice,total,IMAGE);
        //ADD TO ARRAYLIS
        chartGetterSetters.add(p);

        //CHECK IF ARRAYLIST ISNT EMPTY

        if(chartGetterSetters.size()>0)
        {
            int totalPrice = 0;
            int total_qty=0;
            for(int j = 0 ; j < chartGetterSetters.size(); j++) {

                totalPrice += Integer.parseInt(chartGetterSetters.get(j).getPrice_prdct())*Integer.parseInt(chartGetterSetters.get(j).getTotal_quantity()) ;
                total_qty += Integer.parseInt(chartGetterSetters.get(j).getTotal_quantity());
            }
            String tProice=String.valueOf(totalPrice);
            finalprice_upper.setText("Rs "+tProice);
            finalprice_bottom.setText(String.valueOf(total_qty));//totelPriceTV.setText(tProice);
            recyclerView.setAdapter(adapter);

        }
    }
}
</code>```

}

Here is my Adapter Cart

```<code>public class Adapter_chart extends RecyclerView.Adapter<ViewHolder_chart> {
private static final String TAG ="Adapater_chart" ;
ArrayList<Chart_getter_setter> _chartdata;
Context context;
FragmentManager fragmentManager;
String total = "";

public Adapter_chart(Context context, FragmentManager fragmentManager,
    ArrayList<Chart_getter_setter> _chartdata) {
    this.context = context;
    this.fragmentManager = fragmentManager;
    this._chartdata = _chartdata;

    _chartdata = new ArrayList<>();
}

@NonNull
@Override
public ViewHolder_chart onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

    LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
    View view = layoutInflater.inflate(R.layout.chart_single_item, viewGroup, false);
    ViewHolder_chart viewHolder = new ViewHolder_chart(view);
    return viewHolder;

}

@Override
public void onBindViewHolder(@NonNull final ViewHolder_chart viewHolder_chart, final int i) {

    viewHolder_chart.p_name_CHART_tv.setText(_chartdata.get(i).getName_prdct()); // set name of product
    //Replace these two methods
    viewHolder_chart.p_price_CHART_tv.setText(_chartdata.get(i).getPrice_prdct());  // set quantity
    viewHolder_chart.p_quantity_Chart_tv.setText(_chartdata.get(i).getUnit_prdct());  // set price
    ////////////////////////////////
    viewHolder_chart.p_totalITem_CHART_tv.setText(_chartdata.get(i).getTotal_quantity());

    Log.d("Adapter_chart", "bitmap=" + _chartdata.get(i).getImage_prdct());
    //viewHolder_chart.p_img_CHART.setImageBitmap(_chartdata.get(i).getImage_prdct());
    Picasso.get().load(_chartdata.get(i).getImage_prdct()).placeholder(R.drawable.no_image_find).into(viewHolder_chart.p_img_CHART);

    viewHolder_chart.p_add_CHART_tv.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onClick(View v) {
            Log.d(TAG,"Add button is pressed");
            int count_value= Integer.parseInt((String) viewHolder_chart.p_totalITem_CHART_tv.getText());

            count_value++;
            viewHolder_chart.p_totalITem_CHART_tv.setText(Integer.toString(count_value));

            String total_qty_pro= (String) viewHolder_chart.p_totalITem_CHART_tv.getText();
            String prdct_name= (String) _chartdata.get(i).getName_prdct();
            UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

        }
    });
    viewHolder_chart.p_remove_CHART_tv.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onClick(View v) {
            int count_value= Integer.parseInt((String) viewHolder_chart.p_totalITem_CHART_tv.getText());
            count_value--;
            if (count_value<1)
            {
                Log.d(TAG,"Remove button is pressed");

                String name_prdct= (String) viewHolder_chart.p_name_CHART_tv.getText();
                delete_record(name_prdct,context);
                _chartdata.remove(i);
                notifyDataSetChanged();

            }else {
                viewHolder_chart.p_totalITem_CHART_tv.setText(Integer.toString(count_value));
                String total_qty_pro= (String) viewHolder_chart.p_totalITem_CHART_tv.getText();
                String prdct_name= (String) _chartdata.get(i).getName_prdct();
                UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

            }
        }

    viewHolder_chart.item_remove_imageview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name_prdct= (String) viewHolder_chart.p_name_CHART_tv.getText();
            delete_record(name_prdct,context);
            _chartdata.remove(i);
            notifyDataSetChanged();
        }

    });
}
@Override
public int getItemCount() {

    return _chartdata.size();
}
</code>```

}

https://i.stack.imgur.com/FMEcN.jpg

答:
The easiest way is by using Room with LiveData. With these components, you will get updated values when you add, remove or even edit a row in the database table. You can learn these components from here. LiveData - Room also you can read this google codelab.
But if you don't want to use these components(I highly recommend you to use them) I think you can get all rows in your database in your activity onResum() method and update your RecyclerView with new data. </p>

Body:
first of all i'm describing some explanation about my question,
i have two fragments name as "Main Fragment" and second one is " Cart Fragment"

1==> Main Fragment- Contains recyclerview in which data comes from firestore and set in recyclerview, when user click on add or remove button then data is entered and update in sqlite.

2==> Cart Fragment- Contains recyclerview in which data comes from SQLITE and set in recycelerview.

My Question is when i navigate from cart fragment to Main Fragment then First check that any item is already saved in sqlite or not, if exist then get total item quantity from cart fragment of that item(including other data like name, price etc.) and set in main fragmnet.

Here code for Main Fragment Adapter

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    holder.TV_OFF.setText(_mylistdata.get(position).getDiscount()+"% OFF");
   //"Rs "+
    holder.TV_CURNT_PRICE.setText(_mylistdata.get(position).getCurr_price());
    holder.TV_OLD_PRICE.setText(_mylistdata.get(position).getOld_price());
    holder.TV_NAME.setText(_mylistdata.get(position).getName());
    holder.TV_OFFER_DES.setText(_mylistdata.get(position).getOffers_des());
    holder.TV_UNIT.setText(_mylistdata.get(position).getUnit_products()+" Unit");
    Picasso.get().load(_mylistdata.get(position).getImgId()).placeholder(R.drawable.no_image_find).into(holder.imageView);

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

            //Toast.makeText(context, "pos="+prd_id, Toast.LENGTH_SHORT).show();
            holder.add_btn.setVisibility(View.GONE);
            holder.TV_REMOVEITEM.setVisibility(View.VISIBLE);
            holder.TV_TOTALITEM.setVisibility(View.VISIBLE);
            holder.TV_ADDITEM.setVisibility(View.VISIBLE);
            count_value=1;

            holder.TV_TOTALITEM.setText(Integer.toString(count_value));
            // get data from views
            getDataFromViews(position);
            total_qty_pro= (String) holder.TV_TOTALITEM.getText();
            //qty_pro=_mylistdata.get(position).getUnit_products();
            qty_new=qty_pro+" Unit";
            saveData_To_SQLITE(new_name,qty_new,price_pro,price_old,total_qty_pro,image_id,context);

        }

    });
    holder.TV_REMOVEITEM.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {

            //productId= (int) getItemId(position);
            count_value--;
            if (count_value<1)
            {
                Log.d(TAG,"Remove button is pressed");
                holder.add_btn.setVisibility(View.VISIBLE);
                holder.TV_REMOVEITEM.setVisibility(View.GONE);
                holder.TV_TOTALITEM.setVisibility(View.GONE);
                holder.TV_ADDITEM.setVisibility(View.GONE);
                count_value=1;

                String prdct_name= _mylistdata.get(position).getName();

                delete_record(prdct_name,context);

            }else {
                //Data_parsing.setCountText(count_value);
                holder.TV_TOTALITEM.setText(Integer.toString(count_value));

                total_qty_pro= (String) holder.TV_TOTALITEM.getText();
                String prdct_name= _mylistdata.get(position).getName();

                UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

            }

        }
    });
    holder.TV_ADDITEM.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG,"Add button is pressed");
            count_value++;
            //Data_parsing.setCountText(count_value);
            holder.TV_TOTALITEM.setText(Integer.toString(count_value));

            total_qty_pro= (String) holder.TV_TOTALITEM.getText();
            String prdct_name= _mylistdata.get(position).getName();
            UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);
        }

    });
}

Here is my SQLite class in which i define my static methods for saving, updating and delete my data from sqlite

public class SQLITE_RUD {

// Save data to sqlite
public static void  saveData_To_SQLITE(String name_pro, String qty_pro, String price_pro,String price_old, String total_qty_pro, String image_id, Context context) {
    DBAdapter db = new DBAdapter(context);
    db.openDB();
    long result =  db.add(name_pro, qty_pro, price_pro,price_old, total_qty_pro, image_id);
    if (result > 0) {
        Toast.makeText(context, "Data is saved succeffuly", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(context, "Unable to save", Toast.LENGTH_SHORT).show();
    }
    db.closeDB();
}

// update data in sqlite

public static void UPDATE_SQL_DATA(String p_name, String total_qty_pro, Context context)
{
    DBAdapter db=new DBAdapter(context);
    db.openDB();
    try {
        long result=db.update_DB(p_name,total_qty_pro);
        if(result>0)
        {
            Toast.makeText(context, "Updated Sucesfully", Toast.LENGTH_SHORT).show();
        }else
        {
            Toast.makeText(context, "Unable to update", Toast.LENGTH_SHORT).show();
        }
    }catch (Exception e)
    {
        Log.d("MyListAdapter","error_update="+e);
    }
    db.closeDB();
}
// Delete data from SQlite
public static void delete_record(String prdct_name,Context context) {
    //
    DBAdapter db=new DBAdapter(context);
    db.openDB();
    try {
        long result=db.Delete_DB(prdct_name);
        if(result>0)
        {
            Toast.makeText(context, "Deleted Sucesfully", Toast.LENGTH_SHORT).show();
        }else
        {
            Toast.makeText(context, "Unable to Delete", Toast.LENGTH_SHORT).show();
        }
    }catch (Exception e)
    {
        Log.d("MyListAdapter","error_delete="+e);
    }
    db.closeDB();
}

}

Here i create class name ad DBAdapter in which i define methods for saving, updating, and retriving quires.

public class DBAdapter {
Context c;
SQLiteDatabase db;
DbHelper database_helper;   // on create and on upgrade is defined

public DBAdapter(Context c) {
    this.c = c;
    database_helper=new DbHelper(c);

}

//OPEN DB
public void openDB()
{
    try {
        db=database_helper.getWritableDatabase();
        db=database_helper.getReadableDatabase();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
//CLOSE DB
public void closeDB()
{
    try {
        database_helper.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

//INSERT/SAVE
public long add(String P_name,String P_qty,String P_price,String P_OldPrice,String P_Total_qty, String P_Image)
{
    try {
        ContentValues cv=new ContentValues();
        // cv.put(KEY_ItemID, P_id);
        cv.put(KEY_ProductName, P_name);
        cv.put(KEY_ProductQuantity, P_qty);
        cv.put(KEY_ProductPrice, P_price);
        cv.put(KEY_OldPrice, P_OldPrice);
        cv.put(KEY_ProductTotal, P_Total_qty);
        cv.put(KEY_ProductImage,P_Image);
        return db.insert(Table_name, KEY_RowID, cv);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
public long update_DB(String name_prdct, String prdct_TOTAL_QTY)
{
    try
    {
        ContentValues cv=new ContentValues();
        cv.put(KEY_ProductTotal,prdct_TOTAL_QTY);
        return db.update(Table_name,cv,KEY_ProductName +" =?",new String[]{String.valueOf(name_prdct)});
        //return;
    }catch (SQLException e)
    {
        e.printStackTrace();
    }

    return 0;
}

//DELETE
public long Delete_DB(String prdct_name)
{
    try
    {
        return db.delete(Table_name,KEY_ProductName+" =?",new String[]{String.valueOf(prdct_name)});

    }catch (SQLException e)
    {
        e.printStackTrace();
    }

    return 0;
}

//SELECT/RETRIEVE
public Cursor retrieve() {
    String[] columns = {KEY_RowID,KEY_ProductName,KEY_ProductQuantity, KEY_ProductPrice,KEY_OldPrice, KEY_ProductTotal, KEY_ProductImage};
    return db.query(Constants.Table_name, columns, null, null, null, null, null);
}

}

Here is my Cart Fragment

public class CartFragment extends Fragment {
private static final String Tag ="CartFragment" ;
FragmentManager fragmentManager;
RecyclerView recyclerView;
RelativeLayout proceedBtn;
TextView finalprice_bottom, finalprice_upper;
Adapter_chart adapter;
View view;
ArrayList<Chart_getter_setter> chartGetterSetters = new ArrayList<>();

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                         final Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view= inflater.inflate(R.layout.fragment_cart, container, false);
    recyclerView = view.findViewById(R.id.chart_recyclerview);
    proceedBtn=view.findViewById(R.id.bottomChart);

    finalprice_upper=view.findViewById(R.id.price);
    finalprice_bottom =view.findViewById(R.id.FinalPrice_TV);
    proceedBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(savedInstanceState==null) {
                getFragmentManager().beginTransaction().replace(R.id.fragment_container, ProceedFragment.newInstance()).addToBackStack(null).commit();
            }
        }
    });

    adapter = new Adapter_chart(getActivity(), fragmentManager, chartGetterSetters);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayout.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);

    //RETRIEVE
    retrieve_data();

    getActivity().setTitle("Final chart");

    return view;
}
private void retrieve_data() {
    DBAdapter db = new DBAdapter(getContext());
    db.openDB();
    chartGetterSetters.clear();
    //RETRIEVE
    Cursor c = db.retrieve();
    while (c.moveToNext())
    {
        int index_id=c.getColumnIndex(Constants.KEY_RowID);
        int index_name=c.getColumnIndex(Constants.KEY_ProductName);
        int index_qty=c.getColumnIndex(Constants.KEY_ProductQuantity);
        int index_price=c.getColumnIndex(Constants.KEY_ProductPrice);
        int index_oldprice=c.getColumnIndex(Constants.KEY_OldPrice);
        int index_total=c.getColumnIndex(Constants.KEY_ProductTotal);
        int index_image=c.getColumnIndex(Constants.KEY_ProductImage);

        int id=c.getInt(index_id);
        String name=c.getString(index_name);
        String qty=c.getString(index_qty);
        String price=c.getString(index_price);
        String oldPrice=c.getString(index_oldprice);
        String total=c.getString(index_total);
        String IMAGE=c.getString(index_image);

        Chart_getter_setter p=new Chart_getter_setter(name,qty,price,oldPrice,total,IMAGE);
        //ADD TO ARRAYLIS
        chartGetterSetters.add(p);

        //CHECK IF ARRAYLIST ISNT EMPTY

        if(chartGetterSetters.size()>0)
        {
            int totalPrice = 0;
            int total_qty=0;
            for(int j = 0 ; j < chartGetterSetters.size(); j++) {

                totalPrice += Integer.parseInt(chartGetterSetters.get(j).getPrice_prdct())*Integer.parseInt(chartGetterSetters.get(j).getTotal_quantity()) ;
                total_qty += Integer.parseInt(chartGetterSetters.get(j).getTotal_quantity());
            }
            String tProice=String.valueOf(totalPrice);
            finalprice_upper.setText("Rs "+tProice);
            finalprice_bottom.setText(String.valueOf(total_qty));//totelPriceTV.setText(tProice);
            recyclerView.setAdapter(adapter);

        }
    }
}

}

Here is my Adapter Cart

public class Adapter_chart extends RecyclerView.Adapter<ViewHolder_chart> {
private static final String TAG ="Adapater_chart" ;
ArrayList<Chart_getter_setter> _chartdata;
Context context;
FragmentManager fragmentManager;
String total = "";

public Adapter_chart(Context context, FragmentManager fragmentManager,
    ArrayList<Chart_getter_setter> _chartdata) {
    this.context = context;
    this.fragmentManager = fragmentManager;
    this._chartdata = _chartdata;

    _chartdata = new ArrayList<>();
}

@NonNull
@Override
public ViewHolder_chart onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

    LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
    View view = layoutInflater.inflate(R.layout.chart_single_item, viewGroup, false);
    ViewHolder_chart viewHolder = new ViewHolder_chart(view);
    return viewHolder;

}

@Override
public void onBindViewHolder(@NonNull final ViewHolder_chart viewHolder_chart, final int i) {

    viewHolder_chart.p_name_CHART_tv.setText(_chartdata.get(i).getName_prdct()); // set name of product
    //Replace these two methods
    viewHolder_chart.p_price_CHART_tv.setText(_chartdata.get(i).getPrice_prdct());  // set quantity
    viewHolder_chart.p_quantity_Chart_tv.setText(_chartdata.get(i).getUnit_prdct());  // set price
    ////////////////////////////////
    viewHolder_chart.p_totalITem_CHART_tv.setText(_chartdata.get(i).getTotal_quantity());

    Log.d("Adapter_chart", "bitmap=" + _chartdata.get(i).getImage_prdct());
    //viewHolder_chart.p_img_CHART.setImageBitmap(_chartdata.get(i).getImage_prdct());
    Picasso.get().load(_chartdata.get(i).getImage_prdct()).placeholder(R.drawable.no_image_find).into(viewHolder_chart.p_img_CHART);

    viewHolder_chart.p_add_CHART_tv.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onClick(View v) {
            Log.d(TAG,"Add button is pressed");
            int count_value= Integer.parseInt((String) viewHolder_chart.p_totalITem_CHART_tv.getText());

            count_value++;
            viewHolder_chart.p_totalITem_CHART_tv.setText(Integer.toString(count_value));

            String total_qty_pro= (String) viewHolder_chart.p_totalITem_CHART_tv.getText();
            String prdct_name= (String) _chartdata.get(i).getName_prdct();
            UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

        }
    });
    viewHolder_chart.p_remove_CHART_tv.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onClick(View v) {
            int count_value= Integer.parseInt((String) viewHolder_chart.p_totalITem_CHART_tv.getText());
            count_value--;
            if (count_value<1)
            {
                Log.d(TAG,"Remove button is pressed");

                String name_prdct= (String) viewHolder_chart.p_name_CHART_tv.getText();
                delete_record(name_prdct,context);
                _chartdata.remove(i);
                notifyDataSetChanged();

            }else {
                viewHolder_chart.p_totalITem_CHART_tv.setText(Integer.toString(count_value));
                String total_qty_pro= (String) viewHolder_chart.p_totalITem_CHART_tv.getText();
                String prdct_name= (String) _chartdata.get(i).getName_prdct();
                UPDATE_SQL_DATA(prdct_name,total_qty_pro,context);

            }
        }

    viewHolder_chart.item_remove_imageview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name_prdct= (String) viewHolder_chart.p_name_CHART_tv.getText();
            delete_record(name_prdct,context);
            _chartdata.remove(i);
            notifyDataSetChanged();
        }

    });
}
@Override
public int getItemCount() {

    return _chartdata.size();
}

}

https://i.stack.imgur.com/FMEcN.jpg


来源: stackexchange

问:
Is HDInsight cluster setup based on ADLS persistent?
Is HDInsight cluster setup based on ADLS a persistent cluster?

What is the similar storage for ADLS in AWS?

答:
Is HDInsight cluster setup based on ADLS a persistent cluster?

Yes,based on the statements from official document:

BTW,ADLS Gen2 is suggested to gain the improved performances.

What is the similar storage for ADLS in AWS?

You could scan the overview of Data Lakes and Analytics on AWS.Among them,the features of AWS Lake Formation is similar to the ADLS,i think.

ContentLicense: CC BY-SA 4.0


问:
How can I add space between these logos in list
I want to use social media icons and I'm trying to add space between them. I have then in ul and set each li to a different class. I know there's an easier way to go about this using fontawesome link and icons but I just wanted to see if this way works, I'm a beginner I just started coding 2 weeks ago.

I've tried the light-height and nothing happens:

```

<pre class="lang-css prettyprint-override"><code>.contact1 {
    position: absolute;
    display: flex;
    margin: 0;
    padding: 0;
    top: 50%;
    left: 50%;
    transform: translate(-50%.-50%)
}

 .contact1, .contact2, .contact3, .contact4, .contact5 {
    list-style: none;
    border: none;
    position: relative;
    line-height: 50px;
 }
</code>```

答:
I recommend to use proper way of classes in html/css

Here is HTML

```<code><div class="container2">
    <ul>
        <li><img src="facebook.png" alt="facebook" class="facebook"> </li>
        <li><img src="twitter.png" alt="twitter" class="twitter"> </li>
        <li><img src="instagram.png" alt="instagram" class="instagram"> </li>
        <li><img src="twitch.png" alt="twitch" class="twitch"> </li>
    </ul>
</div>
</code>```

Here is CSS:

```<code>.container2 ul{
    position: absolute;
    display: flex;
    justify-content:space-around;
    margin: 0;
    padding: 0;
    top: 50%;
    left: 50%;
    transform: translate(-50% , -50%);
}

.container2 ul li{
    list-style: none;
    border: none;
    position: relative;
    line-height: 50px;
 }
</code>```

Body:
I want to use social media icons and I'm trying to add space between them. I have then in ul and set each li to a different class. I know there's an easier way to go about this using fontawesome link and icons but I just wanted to see if this way works, I'm a beginner I just started coding 2 weeks ago.

I've tried the light-height and nothing happens:

.contact1 {
    position: absolute;
    display: flex;
    margin: 0;
    padding: 0;
    top: 50%;
    left: 50%;
    transform: translate(-50%.-50%)
}

 .contact1, .contact2, .contact3, .contact4, .contact5 {
    list-style: none;
    border: none;
    position: relative;
    line-height: 50px;
 }

Body:
I recommend to use proper way of classes in html/css

Here is HTML

<div class="container2">
    <ul>
        <li><img src="facebook.png" alt="facebook" class="facebook"> </li>
        <li><img src="twitter.png" alt="twitter" class="twitter"> </li>
        <li><img src="instagram.png" alt="instagram" class="instagram"> </li>
        <li><img src="twitch.png" alt="twitch" class="twitch"> </li>
    </ul>
</div>

Here is CSS:

.container2 ul{
    position: absolute;
    display: flex;
    justify-content:space-around;
    margin: 0;
    padding: 0;
    top: 50%;
    left: 50%;
    transform: translate(-50% , -50%);
}

.container2 ul li{
    list-style: none;
    border: none;
    position: relative;
    line-height: 50px;
 }


问:
How do I make an alphabetized list of all distinct words in a file with the number of times each word was used?
I am writing a program using Microsoft Visual C++. In the program I must read in a text file and print out an alphabetized list of all distinct words in that file with the number of times each word was used.

I have looked up different ways to alphabetize a string but they do not work with the way I have my string initialized.

```<code>// What is inside my text file
Any experienced programmer engaged in writing programs for use by others knows
that, once his program is working correctly, good output is a must. Few people
really care how much time and trouble a programmer has spent in designing and
debugging a program. Most people see only the results. Often, by the time a
programmer has finished tackling a difficult problem, any output may look
great. The programmer knows what it means and how to interpret it. However,
the same cannot be said for others, or even for the programmer himself six
months hence.
</code>```

```<code>string lines;
getline(input, lines);      // Stores what is in file into the string
</code>```

I expect an alphabetized list of words with the number of times each word was used. So far, I do not know how to begin this process.

答:
EDIT:

Everyone's answer seems more elegant because of the map's inherent sorting. My answer functions more as a parser, that later sorts the tokens. Therefore my answer is only useful to the extent of a tokenizer or lexer, whereas Everyone's answer is only good for sorted data.

You first probably want to read in the text file. You want to use a streambuf iterator to read in the file(found here).
You will now have a string called content, which is the content of you file. Next you will want to iterate, or loop, over the contents of this string. To do that you'll want to use an iterator. There should be a string outside of the loop that stores the current word. You will iterate over the content string, and each time you hit a letter character, you will add that character to your current word string. Then, once you hit a space character, you will take that current word string, and push it back into the wordString vector. (Note: that means that this will ignore non-letter characters, and that only spaces denote word separation.)

Now that we have a vector of all of our words in strings, we can use std::sort, to sort the vector in alphabetical order.(Note: capitalized words take precedence over lowercase words, and therefore will be sorted first.) Then we will iterate over our vector of stringWords and convert them into Word objects (this is a little heavy-weight), that will store their appearances and the word string. We will push these Word objects into a Word vector, but if we discover a repeat word string, instead of adding it into the Word vector, we'll grab the previous entry and increment its appearance count.

Finally, once this is all done, we can iterate over our Word object vector and output the word followed by its appearances.

Full Code:

```<code>#include <vector>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <algorithm>
#include <string>

class Word //define word object
{
public:
    Word(){appearances = 1;}
    ~Word(){}
    int appearances;
    std::string mWord;
};

bool isLetter(const char x)
{
    return((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z'));
}

int main()
{
    std::string srcFile = "myTextFile.txt"; //what file are we reading
    std::ifstream ifs(srcFile);
    std::string content( (std::istreambuf_iterator<char>(ifs) ),
                       (  std::istreambuf_iterator<char>()    )); //read in the file
    std::vector<std::string> wordStringV; //create a vector of word strings
    std::string current = ""; //define our current word
    for(auto it = content.begin(); it != content.end(); ++it) //iterate over our input
    {
        const char currentChar = *it; //make life easier
        if(currentChar == ' ')
        {
            wordStringV.push_back(current);
            current = "";
            continue;
        }
        else if(isLetter(currentChar))
        {
            current += *it;
        }
    }

    std::sort(wordStringV.begin(), wordStringV.end(), std::less<std::string>());
    std::vector<Word> wordVector;

    for(auto it = wordStringV.begin(); it != wordStringV.end(); ++it) //iterate over wordString vector
    {
        std::vector<Word>::iterator wordIt;
        //see if the current word string has appeared before...
        for(wordIt = wordVector.begin(); wordIt != wordVector.end(); ++wordIt)
        {
            if((*wordIt).mWord == *it)
                break;
        }
        if(wordIt == wordVector.end()) //...if not create a new Word obj
        {
            Word theWord;
            theWord.mWord = *it;
            wordVector.push_back(theWord);
        }
        else //...otherwise increment the appearances.
        {
            ++((*wordIt).appearances);
        }
    }
    //print the words out
    for(auto it = wordVector.begin(); it != wordVector.end(); ++it)
    {
        Word theWord = *it;
        std::cout << theWord.mWord << " " << theWord.appearances << "\n";
    }

    return 0;
}
</code>```

Side Notes

Compiled with g++ version 4.2.1 with target x86_64-apple-darwin, using the compiler flag -std=c++11.

If you don't like iterators you can instead do

```<code>for(int i = 0; i < v.size(); ++i)
{
    char currentChar = vector[i];
}
</code>```

It's important to note that if you are capitalization agnostic simply use std::tolower on the current += *it; statement (ie: current += std::tolower(*it);).

Also, you seem like a beginner and this answer might have been too heavyweight, but you're asking for a basic parser and that is no easy task. I recommend starting by parsing simpler strings like math equations. Maybe make a calculator app.

Body:
I am writing a program using Microsoft Visual C++. In the program I must read in a text file and print out an alphabetized list of all distinct words in that file with the number of times each word was used.

I have looked up different ways to alphabetize a string but they do not work with the way I have my string initialized.

// What is inside my text file
Any experienced programmer engaged in writing programs for use by others knows
that, once his program is working correctly, good output is a must. Few people
really care how much time and trouble a programmer has spent in designing and
debugging a program. Most people see only the results. Often, by the time a
programmer has finished tackling a difficult problem, any output may look
great. The programmer knows what it means and how to interpret it. However,
the same cannot be said for others, or even for the programmer himself six
months hence.

string lines;
getline(input, lines);      // Stores what is in file into the string

I expect an alphabetized list of words with the number of times each word was used. So far, I do not know how to begin this process.

Body:
EDIT:

Everyone's answer seems more elegant because of the map's inherent sorting. My answer functions more as a parser, that later sorts the tokens. Therefore my answer is only useful to the extent of a tokenizer or lexer, whereas Everyone's answer is only good for sorted data.

You first probably want to read in the text file. You want to use a streambuf iterator to read in the file(found here).
You will now have a string called content, which is the content of you file. Next you will want to iterate, or loop, over the contents of this string. To do that you'll want to use an iterator. There should be a string outside of the loop that stores the current word. You will iterate over the content string, and each time you hit a letter character, you will add that character to your current word string. Then, once you hit a space character, you will take that current word string, and push it back into the wordString vector. (Note: that means that this will ignore non-letter characters, and that only spaces denote word separation.)

Now that we have a vector of all of our words in strings, we can use std::sort, to sort the vector in alphabetical order.(Note: capitalized words take precedence over lowercase words, and therefore will be sorted first.) Then we will iterate over our vector of stringWords and convert them into Word objects (this is a little heavy-weight), that will store their appearances and the word string. We will push these Word objects into a Word vector, but if we discover a repeat word string, instead of adding it into the Word vector, we'll grab the previous entry and increment its appearance count.

Finally, once this is all done, we can iterate over our Word object vector and output the word followed by its appearances.

Full Code:

#include <vector>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <algorithm>
#include <string>

class Word //define word object
{
public:
    Word(){appearances = 1;}
    ~Word(){}
    int appearances;
    std::string mWord;
};

bool isLetter(const char x)
{
    return((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z'));
}

int main()
{
    std::string srcFile = "myTextFile.txt"; //what file are we reading
    std::ifstream ifs(srcFile);
    std::string content( (std::istreambuf_iterator<char>(ifs) ),
                       (  std::istreambuf_iterator<char>()    )); //read in the file
    std::vector<std::string> wordStringV; //create a vector of word strings
    std::string current = ""; //define our current word
    for(auto it = content.begin(); it != content.end(); ++it) //iterate over our input
    {
        const char currentChar = *it; //make life easier
        if(currentChar == ' ')
        {
            wordStringV.push_back(current);
            current = "";
            continue;
        }
        else if(isLetter(currentChar))
        {
            current += *it;
        }
    }

    std::sort(wordStringV.begin(), wordStringV.end(), std::less<std::string>());
    std::vector<Word> wordVector;

    for(auto it = wordStringV.begin(); it != wordStringV.end(); ++it) //iterate over wordString vector
    {
        std::vector<Word>::iterator wordIt;
        //see if the current word string has appeared before...
        for(wordIt = wordVector.begin(); wordIt != wordVector.end(); ++wordIt)
        {
            if((*wordIt).mWord == *it)
                break;
        }
        if(wordIt == wordVector.end()) //...if not create a new Word obj
        {
            Word theWord;
            theWord.mWord = *it;
            wordVector.push_back(theWord);
        }
        else //...otherwise increment the appearances.
        {
            ++((*wordIt).appearances);
        }
    }
    //print the words out
    for(auto it = wordVector.begin(); it != wordVector.end(); ++it)
    {
        Word theWord = *it;
        std::cout << theWord.mWord << " " << theWord.appearances << "\n";
    }

    return 0;
}

Side Notes

Compiled with g++ version 4.2.1 with target x86_64-apple-darwin, using the compiler flag -std=c++11.

If you don't like iterators you can instead do

for(int i = 0; i < v.size(); ++i)
{
    char currentChar = vector[i];
}

It's important to note that if you are capitalization agnostic simply use std::tolower on the current += *it; statement (ie: current += std::tolower(*it);).

Also, you seem like a beginner and this answer might have been too heavyweight, but you're asking for a basic parser and that is no easy task. I recommend starting by parsing simpler strings like math equations. Maybe make a calculator app.


问:
Azure ADLS Gen 2 writing to blob storage
I'm having a hard time writing to ADLS Gen 2 blob storage with c#.
Is this feature available?

I'm trying to update my code from ADLS Gen 1 to Gen 1.

This piece of code works fine with ADLS Gen 1

```<code>public static async Task<HttpResponseMessage> Run
                (   [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
                    Binder binder ,
                    TraceWriter log)

    {
var container = "my_container";
var path = container + "/test.txt" ;
using (var writer = await binder.BindAsync<TextWriter>(new BlobAttribute(path)))
{
    writer.Write("Hello there !!!!!");
}
}
</code>```

答: You could also programmatically invoke AzCopy v10, passing the --output-type=json flag to make its output parseable by your C# code.  That works if you're uploading from/downloading to disk and that's what Storage Explorer does. But you'd need to use REST as @mai mentioned if you are uploading from/downloading to in-memory "files" that don't exist on disk.</p>

Body:
I'm having a hard time writing to ADLS Gen 2 blob storage with c#.
Is this feature available?

I'm trying to update my code from ADLS Gen 1 to Gen 1.

This piece of code works fine with ADLS Gen 1

public static async Task<HttpResponseMessage> Run
                (   [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
                    Binder binder ,
                    TraceWriter log)

    {
var container = "my_container";
var path = container + "/test.txt" ;
using (var writer = await binder.BindAsync<TextWriter>(new BlobAttribute(path)))
{
    writer.Write("Hello there !!!!!");
}
}


问:
Making python input search function case insensitive
I'm creating a python 3 search function that accepts input from the user. The user inputs a string, which is then searched in a word document.

I have tested the function with 2 docx files - one with the word "hello" in it and the other with "There".

When I input the words with the exact case as they are in the docx file the search function returns the name of the file - success! However, when I input the words without the correct case I don't get anything returned.

I've seen a few questions on here about case insensitive options but I couldn't really find one that was similar enough to my project. Any help would be much appreciated.

```<code>import os
import docx2txt

os.chdir('c:/users/Says/desktop/projectx')

path = ('c:/users/Says/desktop/projectx')

files = []

x = str(input("search: "))

for file in os.listdir(path):
    if file.endswith('.docx'):
        files.append(file)

for i in range(len(files)):
    text = docx2txt.process(files[i])
    if x in text:
        print (files[i])
</code>```

答:
You could use .lower() to make both strings lower case.

```<code>if x.lower() in text.lower():
    print( files[i] )
</code>```

Body:
I'm creating a python 3 search function that accepts input from the user. The user inputs a string, which is then searched in a word document.

I have tested the function with 2 docx files - one with the word "hello" in it and the other with "There".

When I input the words with the exact case as they are in the docx file the search function returns the name of the file - success! However, when I input the words without the correct case I don't get anything returned.

I've seen a few questions on here about case insensitive options but I couldn't really find one that was similar enough to my project. Any help would be much appreciated.

import os
import docx2txt

os.chdir('c:/users/Says/desktop/projectx')

path = ('c:/users/Says/desktop/projectx')

files = []

x = str(input("search: "))

for file in os.listdir(path):
    if file.endswith('.docx'):
        files.append(file)

for i in range(len(files)):
    text = docx2txt.process(files[i])
    if x in text:
        print (files[i])

Body:
You could use .lower() to make both strings lower case.

if x.lower() in text.lower():
    print( files[i] )


问:
listview onitemclicklistener not working using in activity
Hello friend i have custom listview using arrayadopter in my activity i am using listview on item click listner but problem is that its not working please help me here is my code the tost message which i used in my onitem click listner in my activity is not working what problem is here please tell

my custom  layout for listview code:

```      <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:fab="http://schemas.android.com/apk/res-auto"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <Button
                    android:layout_width="28dp"
                    android:layout_height="28dp"
                    android:id="@+id/versenumber"
                    android:text="1"
                    android:background="@drawable/roundedbutton"/>
                <TextView
                    android:layout_width="match_parent"
                    android:id="@+id/verse"
                    android:layout_gravity="center|top"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:textColor="@color/darkcolor"
                    android:textSize="20sp"
                    android:text="@string/versedisplay"/>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_gravity="top"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/speakverse"
                        android:layout_width="28dp"
                        android:layout_marginTop="10dp"
                        android:layout_height="28dp"
                        fab:srcCompat="@drawable/speak" />

                    <ImageView
                        android:layout_width="28dp"
                        android:layout_height="28dp"
                        android:id="@+id/share"
                        android:paddingTop="-10dp"
                        android:layout_marginTop="10dp"
                        android:src="@drawable/ic_share_black_24dp"/>

                    <ToggleButton
                        android:id="@+id/adbookmark"
                        android:layout_marginTop="10dp"
                        android:layout_width="27dp"
                        android:layout_height="28dp"
                        android:layout_gravity="right"
                        android:background="@drawable/toggle_selector"
                        android:textOff=""
                        android:textOn="" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:textAlignment="center"
                android:layout_gravity="top"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            </LinearLayout>
        </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ALLVERSE">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorAccent"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <TextView
            android:id="@+id/bookname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="20sp"
            android:textColor="#ffffff"
            android:textStyle="bold"
            android:text="ALL VERESE" />
    </android.support.v7.widget.Toolbar>

    <ListView
        android:layout_below="@+id/toolbar"
        android:id="@+id/mylistview"
        android:divider="@null"
        android:dividerHeight="3dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ALLVERSE">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorAccent"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/allversecontent" />

</android.support.design.widget.CoordinatorLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <include
        layout="@layout/allverseappbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

     package bible.swordof.God;

        import android.content.Intent;
        import android.content.SharedPreferences;
        import android.database.Cursor;
        import android.database.sqlite.SQLiteDatabase;
        import android.support.annotation.NonNull;
        import android.support.design.widget.NavigationView;
        import android.support.v4.app.Fragment;
        import android.support.v4.view.GravityCompat;
        import android.support.v4.widget.DrawerLayout;
        import android.support.v7.app.ActionBarDrawerToggle;
        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.support.v7.widget.Toolbar;
        import android.view.MenuItem;
        import android.view.View;
        import android.widget.AdapterView;
        import android.widget.ArrayAdapter;
        import android.widget.GridView;
        import android.widget.ListView;
        import android.widget.TextView;
        import android.widget.Toast;

        import java.util.ArrayList;

        import es.dmoral.toasty.Toasty;

        public class ALLVERSE extends AppCompatActivity  implements NavigationView.OnNavigationItemSelectedListener {
            private ListView listView;
            private ArrayList<String>versenumber;
            private ArrayList<String>verselist;
            private ArrayList<String>id;
            private  ArrayList<String>refernce;
            private DatabaseHelper mDBHelper;
            private SQLiteDatabase mDb;
            private int booknumber;
            private  int chapternumber;
            private  String bookname;
            private TextView booknametitle;
            private  FullverseAdopter adopter;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_allverse);

                Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                booknametitle=findViewById(R.id.bookname);

                Intent mIntent = getIntent();
                booknumber = mIntent.getIntExtra("Boooknumber",0);
                chapternumber= mIntent.getIntExtra("Chapternumber", 0);
                bookname=mIntent.getStringExtra("Bookname");

                booknametitle.setText(bookname.toString() +"   "+  chapternumber);

                //Toast.makeText(this, ""+bookname, Toast.LENGTH_SHORT).show();
                setSupportActionBar(toolbar);
                toolbar.setTitle("ALL VERSE");

                setSupportActionBar(toolbar);
                if (getSupportActionBar() != null) {
                    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                    getSupportActionBar().setDisplayShowHomeEnabled(true);
                }

                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
                drawer.addDrawerListener(toggle);
                toggle.syncState();

                NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
                navigationView.setNavigationItemSelectedListener(this);
                setData();

                listView =findViewById(R.id.list);

                adopter=new FullverseAdopter(this,R.layout.versedisplayrow,versenumber,verselist,refernce,id);

                listView.setAdapter(adopter);

                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();

                    }
                });

            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                // handle arrow click here
                if (item.getItemId() == android.R.id.home) {
                    onBackPressed();

                }

                return super.onOptionsItemSelected(item);
            }

            private void setData() {
                versenumber=new ArrayList<>();
                verselist=new ArrayList<>();
                refernce=new ArrayList<>();
                id=new ArrayList<>();

                mDBHelper = new DatabaseHelper(this);
                mDb = mDBHelper.getReadableDatabase();
                Cursor cursor = mDb.rawQuery("SELECT id, v, t from t_kjv where b="+booknumber+" AND c="+chapternumber+";", new String[]{});
                if(cursor!=null && cursor.getCount() > 0)
                { if (cursor.moveToFirst())
                {
                    do {
                        id.add(cursor.getString(0));
                        versenumber.add(cursor.getString(1));
                        verselist.add(cursor.getString(2));

                        refernce.add(bookname+" "+chapternumber);

                    }

                    while (cursor.moveToNext());
                }
                }
            }

            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                // Handle navigation view item clicks here.
                Fragment fragment;
                int id = item.getItemId();

                if (id == R.id.home) {

                    Intent intent=new Intent(this,MainActivity.class);
                    startActivity(intent);

                } else if (id == R.id.favoruite)
                { Intent intent=new Intent(this,Favourite.class);
                    startActivity(intent);
                }  else if (id == R.id.nav_manage) {

                } else if (id == R.id.nav_share) {

                } else if (id == R.id.nav_send) {

                }
                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                drawer.closeDrawer(GravityCompat.START);
                return true;
            }

        }

    My adopter customadopter class:
    package bible.swordof.God;

    import android.app.Activity;
    import android.content.ContentValues;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.graphics.Color;
    import android.opengl.Visibility;
    import android.preference.PreferenceManager;
    import android.speech.tts.TextToSpeech;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.CompoundButton;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.ToggleButton;

    import com.amulyakhare.textdrawable.TextDrawable;
    import com.amulyakhare.textdrawable.util.ColorGenerator;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Locale;

    import es.dmoral.toasty.Toasty;
    import petrov.kristiyan.colorpicker.ColorPicker;

    import static android.content.Context.MODE_PRIVATE;
    import static android.database.sqlite.SQLiteDatabase.CONFLICT_NONE;
    import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
    import static android.support.constraint.Constraints.TAG;
    import static android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext;
    import static android.support.v4.content.ContextCompat.startActivity;

    public class FullverseAdopter extends ArrayAdapter<String> {
        private ALLVERSE activity;

        private List<String> versenumber;
        private List<String>verseid;
        private List<String> verselist;
        private List<String> refernce;
        TextToSpeech textToSpeech;
        private DatabaseHelper mDBHelper;
        private SQLiteDatabase mDb;
        private  boolean ischeckd;
        String My_PREF="MY_PREF";

    public  String ex="switch";

        //check for availabe language
        int result;

        public FullverseAdopter(ALLVERSE context, int resource, List<String> versenumber, List<String> verselist, List<String> refernce, List<String>verseid) {
            super(context, resource, versenumber);
            this.activity = context;
            this.versenumber = versenumber;
            this.verselist = verselist;
            this.refernce = refernce;
            this.verseid=verseid;

        }

        @Override
        public int getCount() {
            return versenumber.size();
        }

        @Override
        public String getItem(int position) {
            return versenumber.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, final ViewGroup parent) {
            final ViewHolder holder;
            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            // If holder not exist then locate all view from UI file.
            if (convertView == null) {
                // inflate UI from XML file
                 convertView = inflater.inflate(R.layout.versedisplayrow, parent, false);
                // get all UI view
                holder = new ViewHolder(convertView);
                // set tag for holder

                holder.versenumber = (TextView) convertView.findViewById(R.id.versenumber);
                holder.verselist = (TextView) convertView.findViewById(R.id.verse);
                holder.addfavoruite=(ToggleButton)convertView.findViewById(R.id.adbookmark);

                convertView.setTag(holder);
            } else {
                // if holder created, get tag from view
                holder = (ViewHolder) convertView.getTag();
            }
            holder.versenumber.setText(versenumber.get(position));
            holder.verselist.setText(verselist.get(position));

    //verselist highlight

            //share verse
            holder.share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toasty.info(activity, "Sharing a verse.", Toast.LENGTH_SHORT, true).show();
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, refernce.get(position) + ":" + versenumber.get(position) + '\n'   + verselist.get(position));
                    sendIntent.setType("text/plain");
                    activity.startActivity(sendIntent);

                }
            });

    //add in favourite
          holder.addfavoruite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    if(isChecked){
                        mDBHelper = new DatabaseHelper(activity);
                        mDb = mDBHelper.getWritableDatabase();
                        ContentValues contentValues=new ContentValues();
                      contentValues.put("id",verseid.get(position));
                      contentValues.put("bookname",refernce.get(position));
                       contentValues.put("versenumber",versenumber.get(position));
                       contentValues.put("verse",verselist.get(position));
                       long check=mDb.insert("favourite",null,contentValues);
                       Log.d("MY_TAG","DB IS NOW "+check);

                       Toasty.success(activity, "Added in favouite", Toast.LENGTH_SHORT, true).show();

                    }else {

                        mDBHelper = new DatabaseHelper(activity);
                        mDb = mDBHelper.getWritableDatabase();
                        long delete= mDb.delete("favourite","id=?",new String[]{verseid.get(position)});
                        Toasty.error(activity, "Remove in favouite", Toast.LENGTH_SHORT, true).show();
                    }

                }
            });

            textToSpeech = new TextToSpeech(activity, new TextToSpeech.OnInitListener() {
                @Override
                public void onInit(int status) {

                    if (status == TextToSpeech.SUCCESS) {
                        result = textToSpeech.setLanguage(Locale.ENGLISH);
                    } else {

                        Toast.makeText(activity, "YOUR DEVICE NOT SUPPORTED", Toast.LENGTH_SHORT).show();
                    }
                }
            });

            //My toggle button

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

                    Toast.makeText(activity, "I AM CLICKED", Toast.LENGTH_SHORT).show();

                    if (result == TextToSpeech.LANG_NOT_SUPPORTED || result == TextToSpeech.LANG_MISSING_DATA) {

                        Toast.makeText(activity, "Language not supported or Missing", Toast.LENGTH_SHORT).show();

                    } else {

                        textToSpeech.speak(verselist.get(position), TextToSpeech.QUEUE_FLUSH, null);

                    }
                }
            });

            return convertView;
        }

        static class ViewHolder {
            private TextView versenumber;
            private TextView verselist;

            private ImageView share;
            private  ToggleButton addfavoruite;
            private ImageView speakverse;

            public ViewHolder(View v) {
                versenumber = (TextView) v.findViewById(R.id.versenumber);
                verselist = (TextView) v.findViewById(R.id.verse);
                share = (ImageView) v.findViewById(R.id.share);
                speakverse = (ImageView) v.findViewById(R.id.speakverse);
                addfavoruite=(ToggleButton)v.findViewById(R.id.adbookmark);

            }

        }
        public boolean CheckIsDataAlreadyInDBorNot(String TableName,  String dbfield, String fieldValue) {

            mDBHelper = new DatabaseHelper(activity);
            mDb = mDBHelper.getReadableDatabase();
            String Query = "Select * from " + TableName + " where " + dbfield + " = " + fieldValue;
            Cursor cursor = mDb.rawQuery(Query, null);
            if(cursor.getCount() <= 0){
                cursor.close();

                Toast.makeText(activity, "false", Toast.LENGTH_SHORT).show();
                return false;
            }else {

                Toast.makeText(activity, "TRUE", Toast.LENGTH_SHORT).show();

            }
            cursor.close();

            return true;
        }
        public  void opecolorpicker(){
            ColorPicker colorPicker = new ColorPicker(activity);
            ArrayList<String>colors=new ArrayList<>();
            colors.add("#FF0000");
            colors.add("#FFEC33");
            colors.add("#3C33FF");
            colors.add("#DA33FF");
            colors.add("#33FF99");
            colors.add("#90FF33");
            colors.add("#DD33FF");
            colors.add("#F0B27A");
            colors.add("#DAF7A6");
            colors.add("#34495E");
            colorPicker.setColors(colors).setTitle("HIGHLIGHT VERSE").setRoundColorButton(true).setOnChooseColorListener(new ColorPicker.OnChooseColorListener() {
                @Override
                public void onChooseColor(int position, int color) {

                    Toast.makeText(activity, ""+color, Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onCancel() {

                }
            }).show();

        }

    }
```

答:
Use this:

```<code>listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
    }
});
</code>```

Instead of:

```<code>listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
    }
});
</code>```

Body:
Hello friend i have custom listview using arrayadopter in my activity i am using listview on item click listner but problem is that its not working please help me here is my code the tost message which i used in my onitem click listner in my activity is not working what problem is here please tell

my custom  layout for listview code:

      <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:fab="http://schemas.android.com/apk/res-auto"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <Button
                    android:layout_width="28dp"
                    android:layout_height="28dp"
                    android:id="@+id/versenumber"
                    android:text="1"
                    android:background="@drawable/roundedbutton"/>
                <TextView
                    android:layout_width="match_parent"
                    android:id="@+id/verse"
                    android:layout_gravity="center|top"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:textColor="@color/darkcolor"
                    android:textSize="20sp"
                    android:text="@string/versedisplay"/>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_gravity="top"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/speakverse"
                        android:layout_width="28dp"
                        android:layout_marginTop="10dp"
                        android:layout_height="28dp"
                        fab:srcCompat="@drawable/speak" />

                    <ImageView
                        android:layout_width="28dp"
                        android:layout_height="28dp"
                        android:id="@+id/share"
                        android:paddingTop="-10dp"
                        android:layout_marginTop="10dp"
                        android:src="@drawable/ic_share_black_24dp"/>

                    <ToggleButton
                        android:id="@+id/adbookmark"
                        android:layout_marginTop="10dp"
                        android:layout_width="27dp"
                        android:layout_height="28dp"
                        android:layout_gravity="right"
                        android:background="@drawable/toggle_selector"
                        android:textOff=""
                        android:textOn="" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:textAlignment="center"
                android:layout_gravity="top"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            </LinearLayout>
        </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ALLVERSE">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorAccent"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <TextView
            android:id="@+id/bookname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="20sp"
            android:textColor="#ffffff"
            android:textStyle="bold"
            android:text="ALL VERESE" />
    </android.support.v7.widget.Toolbar>

    <ListView
        android:layout_below="@+id/toolbar"
        android:id="@+id/mylistview"
        android:divider="@null"
        android:dividerHeight="3dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ALLVERSE">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorAccent"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/allversecontent" />

</android.support.design.widget.CoordinatorLayout>

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <include
        layout="@layout/allverseappbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

     package bible.swordof.God;

        import android.content.Intent;
        import android.content.SharedPreferences;
        import android.database.Cursor;
        import android.database.sqlite.SQLiteDatabase;
        import android.support.annotation.NonNull;
        import android.support.design.widget.NavigationView;
        import android.support.v4.app.Fragment;
        import android.support.v4.view.GravityCompat;
        import android.support.v4.widget.DrawerLayout;
        import android.support.v7.app.ActionBarDrawerToggle;
        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.support.v7.widget.Toolbar;
        import android.view.MenuItem;
        import android.view.View;
        import android.widget.AdapterView;
        import android.widget.ArrayAdapter;
        import android.widget.GridView;
        import android.widget.ListView;
        import android.widget.TextView;
        import android.widget.Toast;

        import java.util.ArrayList;

        import es.dmoral.toasty.Toasty;

        public class ALLVERSE extends AppCompatActivity  implements NavigationView.OnNavigationItemSelectedListener {
            private ListView listView;
            private ArrayList<String>versenumber;
            private ArrayList<String>verselist;
            private ArrayList<String>id;
            private  ArrayList<String>refernce;
            private DatabaseHelper mDBHelper;
            private SQLiteDatabase mDb;
            private int booknumber;
            private  int chapternumber;
            private  String bookname;
            private TextView booknametitle;
            private  FullverseAdopter adopter;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_allverse);

                Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                booknametitle=findViewById(R.id.bookname);

                Intent mIntent = getIntent();
                booknumber = mIntent.getIntExtra("Boooknumber",0);
                chapternumber= mIntent.getIntExtra("Chapternumber", 0);
                bookname=mIntent.getStringExtra("Bookname");

                booknametitle.setText(bookname.toString() +"   "+  chapternumber);

                //Toast.makeText(this, ""+bookname, Toast.LENGTH_SHORT).show();
                setSupportActionBar(toolbar);
                toolbar.setTitle("ALL VERSE");

                setSupportActionBar(toolbar);
                if (getSupportActionBar() != null) {
                    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                    getSupportActionBar().setDisplayShowHomeEnabled(true);
                }

                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
                drawer.addDrawerListener(toggle);
                toggle.syncState();

                NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
                navigationView.setNavigationItemSelectedListener(this);
                setData();

                listView =findViewById(R.id.list);

                adopter=new FullverseAdopter(this,R.layout.versedisplayrow,versenumber,verselist,refernce,id);

                listView.setAdapter(adopter);

                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();

                    }
                });

            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                // handle arrow click here
                if (item.getItemId() == android.R.id.home) {
                    onBackPressed();

                }

                return super.onOptionsItemSelected(item);
            }

            private void setData() {
                versenumber=new ArrayList<>();
                verselist=new ArrayList<>();
                refernce=new ArrayList<>();
                id=new ArrayList<>();

                mDBHelper = new DatabaseHelper(this);
                mDb = mDBHelper.getReadableDatabase();
                Cursor cursor = mDb.rawQuery("SELECT id, v, t from t_kjv where b="+booknumber+" AND c="+chapternumber+";", new String[]{});
                if(cursor!=null && cursor.getCount() > 0)
                { if (cursor.moveToFirst())
                {
                    do {
                        id.add(cursor.getString(0));
                        versenumber.add(cursor.getString(1));
                        verselist.add(cursor.getString(2));

                        refernce.add(bookname+" "+chapternumber);

                    }

                    while (cursor.moveToNext());
                }
                }
            }

            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                // Handle navigation view item clicks here.
                Fragment fragment;
                int id = item.getItemId();

                if (id == R.id.home) {

                    Intent intent=new Intent(this,MainActivity.class);
                    startActivity(intent);

                } else if (id == R.id.favoruite)
                { Intent intent=new Intent(this,Favourite.class);
                    startActivity(intent);
                }  else if (id == R.id.nav_manage) {

                } else if (id == R.id.nav_share) {

                } else if (id == R.id.nav_send) {

                }
                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                drawer.closeDrawer(GravityCompat.START);
                return true;
            }

        }

    My adopter customadopter class:
    package bible.swordof.God;

    import android.app.Activity;
    import android.content.ContentValues;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.graphics.Color;
    import android.opengl.Visibility;
    import android.preference.PreferenceManager;
    import android.speech.tts.TextToSpeech;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.CompoundButton;
    import android.widget.ImageView;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.ToggleButton;

    import com.amulyakhare.textdrawable.TextDrawable;
    import com.amulyakhare.textdrawable.util.ColorGenerator;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Locale;

    import es.dmoral.toasty.Toasty;
    import petrov.kristiyan.colorpicker.ColorPicker;

    import static android.content.Context.MODE_PRIVATE;
    import static android.database.sqlite.SQLiteDatabase.CONFLICT_NONE;
    import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
    import static android.support.constraint.Constraints.TAG;
    import static android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext;
    import static android.support.v4.content.ContextCompat.startActivity;

    public class FullverseAdopter extends ArrayAdapter<String> {
        private ALLVERSE activity;

        private List<String> versenumber;
        private List<String>verseid;
        private List<String> verselist;
        private List<String> refernce;
        TextToSpeech textToSpeech;
        private DatabaseHelper mDBHelper;
        private SQLiteDatabase mDb;
        private  boolean ischeckd;
        String My_PREF="MY_PREF";

    public  String ex="switch";

        //check for availabe language
        int result;

        public FullverseAdopter(ALLVERSE context, int resource, List<String> versenumber, List<String> verselist, List<String> refernce, List<String>verseid) {
            super(context, resource, versenumber);
            this.activity = context;
            this.versenumber = versenumber;
            this.verselist = verselist;
            this.refernce = refernce;
            this.verseid=verseid;

        }

        @Override
        public int getCount() {
            return versenumber.size();
        }

        @Override
        public String getItem(int position) {
            return versenumber.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, final ViewGroup parent) {
            final ViewHolder holder;
            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            // If holder not exist then locate all view from UI file.
            if (convertView == null) {
                // inflate UI from XML file
                 convertView = inflater.inflate(R.layout.versedisplayrow, parent, false);
                // get all UI view
                holder = new ViewHolder(convertView);
                // set tag for holder

                holder.versenumber = (TextView) convertView.findViewById(R.id.versenumber);
                holder.verselist = (TextView) convertView.findViewById(R.id.verse);
                holder.addfavoruite=(ToggleButton)convertView.findViewById(R.id.adbookmark);

                convertView.setTag(holder);
            } else {
                // if holder created, get tag from view
                holder = (ViewHolder) convertView.getTag();
            }
            holder.versenumber.setText(versenumber.get(position));
            holder.verselist.setText(verselist.get(position));

    //verselist highlight

            //share verse
            holder.share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toasty.info(activity, "Sharing a verse.", Toast.LENGTH_SHORT, true).show();
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, refernce.get(position) + ":" + versenumber.get(position) + '\n'   + verselist.get(position));
                    sendIntent.setType("text/plain");
                    activity.startActivity(sendIntent);

                }
            });

    //add in favourite
          holder.addfavoruite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    if(isChecked){
                        mDBHelper = new DatabaseHelper(activity);
                        mDb = mDBHelper.getWritableDatabase();
                        ContentValues contentValues=new ContentValues();
                      contentValues.put("id",verseid.get(position));
                      contentValues.put("bookname",refernce.get(position));
                       contentValues.put("versenumber",versenumber.get(position));
                       contentValues.put("verse",verselist.get(position));
                       long check=mDb.insert("favourite",null,contentValues);
                       Log.d("MY_TAG","DB IS NOW "+check);

                       Toasty.success(activity, "Added in favouite", Toast.LENGTH_SHORT, true).show();

                    }else {

                        mDBHelper = new DatabaseHelper(activity);
                        mDb = mDBHelper.getWritableDatabase();
                        long delete= mDb.delete("favourite","id=?",new String[]{verseid.get(position)});
                        Toasty.error(activity, "Remove in favouite", Toast.LENGTH_SHORT, true).show();
                    }

                }
            });

            textToSpeech = new TextToSpeech(activity, new TextToSpeech.OnInitListener() {
                @Override
                public void onInit(int status) {

                    if (status == TextToSpeech.SUCCESS) {
                        result = textToSpeech.setLanguage(Locale.ENGLISH);
                    } else {

                        Toast.makeText(activity, "YOUR DEVICE NOT SUPPORTED", Toast.LENGTH_SHORT).show();
                    }
                }
            });

            //My toggle button

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

                    Toast.makeText(activity, "I AM CLICKED", Toast.LENGTH_SHORT).show();

                    if (result == TextToSpeech.LANG_NOT_SUPPORTED || result == TextToSpeech.LANG_MISSING_DATA) {

                        Toast.makeText(activity, "Language not supported or Missing", Toast.LENGTH_SHORT).show();

                    } else {

                        textToSpeech.speak(verselist.get(position), TextToSpeech.QUEUE_FLUSH, null);

                    }
                }
            });

            return convertView;
        }

        static class ViewHolder {
            private TextView versenumber;
            private TextView verselist;

            private ImageView share;
            private  ToggleButton addfavoruite;
            private ImageView speakverse;

            public ViewHolder(View v) {
                versenumber = (TextView) v.findViewById(R.id.versenumber);
                verselist = (TextView) v.findViewById(R.id.verse);
                share = (ImageView) v.findViewById(R.id.share);
                speakverse = (ImageView) v.findViewById(R.id.speakverse);
                addfavoruite=(ToggleButton)v.findViewById(R.id.adbookmark);

            }

        }
        public boolean CheckIsDataAlreadyInDBorNot(String TableName,  String dbfield, String fieldValue) {

            mDBHelper = new DatabaseHelper(activity);
            mDb = mDBHelper.getReadableDatabase();
            String Query = "Select * from " + TableName + " where " + dbfield + " = " + fieldValue;
            Cursor cursor = mDb.rawQuery(Query, null);
            if(cursor.getCount() <= 0){
                cursor.close();

                Toast.makeText(activity, "false", Toast.LENGTH_SHORT).show();
                return false;
            }else {

                Toast.makeText(activity, "TRUE", Toast.LENGTH_SHORT).show();

            }
            cursor.close();

            return true;
        }
        public  void opecolorpicker(){
            ColorPicker colorPicker = new ColorPicker(activity);
            ArrayList<String>colors=new ArrayList<>();
            colors.add("#FF0000");
            colors.add("#FFEC33");
            colors.add("#3C33FF");
            colors.add("#DA33FF");
            colors.add("#33FF99");
            colors.add("#90FF33");
            colors.add("#DD33FF");
            colors.add("#F0B27A");
            colors.add("#DAF7A6");
            colors.add("#34495E");
            colorPicker.setColors(colors).setTitle("HIGHLIGHT VERSE").setRoundColorButton(true).setOnChooseColorListener(new ColorPicker.OnChooseColorListener() {
                @Override
                public void onChooseColor(int position, int color) {

                    Toast.makeText(activity, ""+color, Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onCancel() {

                }
            }).show();

        }

    }

Body:
Use this:

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
    }
});

Instead of:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(ALLVERSE.this, "LIFE RUNS ON CODE", Toast.LENGTH_SHORT).show();
    }
});