Hello friend i am new in android i want to know how to save ToggleButton state in custom ArrayAdapter i create custom ListView with help of ArrayAdapter now i want how save its state in Adapter here is my code pleae explain what logic used to achieve this goal i am on beginner level don't how to achieve this goal?

package bible.swordof.God;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.opengl.Visibility;
import android.preference.PreferenceManager;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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 com.hitomi.cmlibrary.CircleMenu;
import com.hitomi.cmlibrary.OnMenuSelectedListener;
import com.hitomi.cmlibrary.OnMenuStatusChangeListener;

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

import es.dmoral.toasty.Toasty;

import static android.content.Context.MODE_PRIVATE;
import static android.database.sqlite.SQLiteDatabase.CONFLICT_NONE;
import static;
import static;
import static;
import static;

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 save;
    public static final String MyPREFERENCES = "MyPrefs";

    //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;


    public int getCount() {
        return versenumber.size();

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

    public long getItemId(int position) {
        return position;

    public View getView(final int position, View convertView, 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(;
            holder.verselist = (TextView) convertView.findViewById(;

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

        //share verse
        holder.share.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
      , "Sharing a verse.", Toast.LENGTH_SHORT, true).show();
                Intent sendIntent = new Intent();
                sendIntent.putExtra(Intent.EXTRA_TEXT, refernce.get(position) + ":" + versenumber.get(position) + '\n' + verselist.get(position));


        textToSpeech = new TextToSpeech(activity, new TextToSpeech.OnInitListener() {
            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.bookmark.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {

                } else {

        //mDBHelper = new DatabaseHelper(activity);
        //mDb = mDBHelper.getWritableDatabase();

        //ContentValues contentValues=new ContentValues();
        //long check=mDb.insert("favourite",null,contentValues);

        //Log.d("MY_TAG","DB IS NOW "+check);

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

        holder.speakverse.setOnClickListener(new View.OnClickListener() {
            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);


        /* holder.removebookmark.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

             mDBHelper = new DatabaseHelper(activity);
               mDb = mDBHelper.getWritableDatabase();

              // long delete= mDb.delete("favourite","id=?",new String[]{verseid.get(position)});

               //Toasty.error(activity, "Remove in favouite"+delete, Toast.LENGTH_SHORT, true).show();

        return convertView;

    static class ViewHolder {
        private ToggleButton favourite;
        private TextView versenumber;
        private TextView verselist;
        private CircleMenu circleMenu;
        private ImageView share;

        //toggle button
        public ToggleButton bookmark;

        private boolean defaultvalue;

        private ALLVERSE activity;
        private ImageView speakverse;

        public ViewHolder(View v) {
            versenumber = (TextView) v.findViewById(;
            verselist = (TextView) v.findViewById(;
            share = (ImageView) v.findViewById(;
            bookmark = (ToggleButton) v.findViewById(;
            speakverse = (ImageView) v.findViewById(;

  • 輸給o時咣 回复