title: how to add selected value in arraylist and remove unselected value from arraylist
body: <p>I have a 'ListView' with one button. When the user clicks on the button I added the selected position value in arraylist.But second time when user click's on the same button i want to remove this button entry from arraylist how to do this.This is my code snipet</p>
  
  <pre><code>@Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
          convertView = layoutInflater.inflate(R.layout.single_row, null);
  
  
      }
      TextView msg = (TextView) convertView.findViewById(R.id.tv_wishdata);
      msg.setText(al.get(position));
      ArrayList arrayList = new ArrayList();
  
      final ArrayList list = new ArrayList&lt;String&gt;();
      final   ImageView   iv = (ImageView) convertView.findViewById(R.id.iv_myImageview);
      final ListView lis = (ListView) convertView.findViewById(R.id.listView);
      Boolean click = true;
      iv.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              List&lt;String&gt; listOfFavoritePhrases = new ArrayList&lt;String&gt;();
              //check boolean value
              if (click) {
                  iv.setBackgroundResource(R.drawable.thirdwish);
                  /*TinyDB tinyDB = new TinyDB(context);
                  tinyDB.putString("msg", al  .get(position));
  */            // al.add(al.get(position))
  
                  temp.add(al.get(position));
  
                  Log.d("ARRAY DATA", "" + temp);
                  Log.d("ARRAY SIZE", "" + temp.size());
  
                  /*ContentValues contentValues = new ContentValues();
                  contentValues.put("item",al.get(position));
                  Log.d("Contentvalues",""+contentValues.toString());
                  db.insert("favorite",null,contentValues);*/
  
                  sp = context.getSharedPreferences("mypref",Context.MODE_APPEND);
                  SharedPreferences.Editor editor = sp.edit();
                  editor.putString("phrases", TextUtils.join(",", temp.toArray()));
                  Log.d("Shared Data", "" + sp.getString("phrases", ""));
                  editor.commit();
                  click = false;
  
              }
              else {
                  click = true;
                  temp.remove(al.get(position));
                  iv.setBackgroundResource(R.drawable.onewish);
                 // db.rawQuery("delete from favorite where item like'%" + al.get(position) + "%'", null);
                  Log.d("QUERY", "" + al.get(position));
                  // al.remove(position);
                  notifyDataSetChanged();
              }
              // Toast.makeText(context, "imageview clicked", Toast.LENGTH_LONG).show();
          }
      });
      return convertView;
  }
  </code></pre>