title: EditText get selection index with button click
body: <p>I want to implement tag-supported plain text editor.</p>
  
  <p>For that, like stackoverflow input panel, when user selects text and clicks "bold" button then the selected text is replaced into <code>&lt;b&gt; selected text &lt;/b&gt;</code> or <code>** selected text **</code>.</p>
  
  <p>To get the start and end index of text, below code is used.</p>
  
  <pre><code>int startIndex =  _editTextContent.getSelectionStart();
  int endIndex = _editTextContent.getSelectionEnd();
  </code></pre>
  
  <p>but, when I click the button, even the GUI still shows text selection marker, the same start and end values are given. </p>
  
  <p>I found that <code>Button</code> works fine but <code>ListView</code> with its item click events are not give proper value.
  I use <a href="https://github.com/sephiroth74/HorizontalVariableListView" rel="nofollow">HListView</a> for adapting to various resolution. FYI, the control is almost same as <code>ListView</code> control.</p>
  
  <p>The item Click event is as below.</p>
  
  <pre><code>public void onItemClick(it.sephiroth.android.library.widget.AdapterView&lt;?&gt; parent, View view, int position, long id) {
  if (_keys.getList().get(position).getId().equals("bold")) {
          try {
              _editTextContent.requestFocus();
              int startIndex =  _editTextContent.getSelectionStart();
              int endIndex = _editTextContent.getSelectionEnd();
              if (startIndex != endIndex){
                  _editTextContent.getText().replace(startIndex, endIndex, "**" + _editTextContent.getText().subSequence(startIndex, endIndex) + "**");
                  _editTextContent.setSelection(endIndex + 4);
  
              }
          } catch (Exception ignore) {
          }
      }
  }
  </code></pre>
  
  <p>may be the button click changes focus to button so that the EditText control is switched from <em>selection</em> status to normal status.</p>
  
  <p>What is the workaround to do?</p>
  
  <p>Note that I'm develping based on the API 9, so that I cannot use <code>textIsSelectable</code> attribute.</p>