title: Saving ToggleButton state in ListView by using SharedPreferences
body: <p>I want to save my ToggleButton state by SharedPreferences at this below codes.
  Please guide me.
  Thanks so much.</p>
  
  <pre>
  public class MyAdapterList extends BaseAdapter {
  
      private Context context;
      private List text;
  
  
  
      public MyAdapterList(Context context, List text) {
          this.context = context;
          this.text = text;
      }
  
      @Override
      public int getCount() {
          return text.size();
      }
  
      @Override
      public Object getItem(int position) {
          return text.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View view = inflater.inflate(R.layout.item_view, null, false);
          TextView tv = (TextView) view.findViewById(R.id.textView);
          tv.setText(text.get(position));
          Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/b_titr.ttf");
          tv.setTypeface(tf);
          tv.setTextColor(Color.parseColor("#003366"));
          tv.setTypeface(tv.getTypeface(), Typeface.BOLD);
  
  
          final ToggleButton toggleButton = (ToggleButton) view.findViewById(R.id.t_button);
  
          final MyDatabaseHelper myDatabaseHelper = new MyDatabaseHelper(context);
  
          toggleButton.setBackgroundResource(R.drawable.favorite_not_selected);
  
          toggleButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if (toggleButton.isChecked()) {
  
  
                      myDatabaseHelper.insert(text.get(position));
  
                      toggleButton.setBackgroundResource(R.drawable.favorite_selected);
                      Toast.makeText(context, "Was added to the list of favorites", Toast.LENGTH_SHORT).show();
  
  
                  } else {
  
  
                      myDatabaseHelper.deletedData(text.get(position));
                      Toast.makeText(context, "Removed from favorites", Toast.LENGTH_SHORT).show();
                      toggleButton.setBackgroundResource(R.drawable.favorite_not_selected);
  
  
                  }
  
              }
          });
  
  
  
          return view;
  
  
      }
  
  
  }
  
  
  </pre>