title: Android listview change item selected state in adapter
body: <p>I have <code>ListView</code> with single choice mode. I make set selection when the user clicks on a list item and it works. Now I need to:</p>
  
  <ol>
  <li>make set selection when the user clicks on the play button in <code>ListView</code> item.</li>
  <li>do it in my <code>ListView</code> adapter.</li>
  <li>unselect the previous item and select the item where the user clicked on the play button.</li>
  </ol>
  
  <p>I tried a few different solutions and they do not work.
  In some case I make multi-select and in some cases I can't select an item.
  <a href="https://i.stack.imgur.com/6p6JM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6p6JM.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>xml</p>
  </blockquote>
  
  <pre><code>&lt;ListView
      android:id="@+id/menu_list_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/listen_price_button"
      android:background="@color/rose"
      android:paddingBottom="5dp"
      android:paddingLeft="11dp"
      android:paddingRight="11dp"
      android:paddingTop="10dp"
      android:scrollbars="none"
      android:drawSelectorOnTop="false"
      android:choiceMode="singleChoice"
      /&gt;
  </code></pre>
  
  <blockquote>
    <p>Selection code used in activity (works fine)</p>
  </blockquote>
  
  <pre><code>// handle click on list view item
  listMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          view.setSelected(true);
          setDetailsData(position);
          mSelectedPosition = position;
      }
  });
  </code></pre>
  
  <blockquote>
    <p>play button code in adapter</p>
  </blockquote>
  
  <pre><code>viewHolder.playImage.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              Listen currentItem = mListenList.get(position);
              if (currentItem.isPurchased() || currentItem.isFree()) {
                  Intent intent = new Intent(mContext, ListenDetailActivity.class);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.putExtra("listen_item", currentItem);
                  intent.putExtra("listen_list", mListenList);
                  mContext.startActivity(intent);
              } else {
                  try {
                      mHelper.launchPurchaseFlow((Activity) mContext, currentItem.getSku(), 1001,
                              mPurchaseFinishedListener, "");
                  } catch (IabHelper.IabAsyncInProgressException e) {
                      Log.e(TAG, "Error launching purchase flow. Another async operation in progress.");
                  }
              }
          }
  });
  </code></pre>
  
  <p>what I tried to add on play button and it do not work</p>
  
  <pre><code> list.clearChoices();
      list.requestLayout();
      finalConvertView.setSelected(true);
  </code></pre>
  
  <p>if i add only  <code>finalConvertView.setSelected(true);</code> it make multiselect</p>
  
  <p>also i tried to unselect all then to select one but it also do not work</p>
  
  <pre><code> for ( int i=0; i&lt; list.getCount(); i++ ) {
  
                     list.setItemChecked(i, false);
  
    }
  finalConvertView.setSelected(true);
  </code></pre>