title: how to get selected item from ListView on Java, Android
body: <p>I have a ListView with adapter:</p>
  
  <pre><code>ListView names=(ListView)findViewById(R.id.listViewItems);
  
  String[] items=new String[mMusicData.size()];
  mMusicData.keySet().toArray(items);
  
  ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_single_choice, new String[]{"A", "B", "C"});
  names.setAdapter(adapter);
  </code></pre>
  
  <p>And when I try to get id of selected item in other function I always got -1:</p>
  
  <pre><code>Log.e("1", String.valueOf(names.getSelectedItemPosition()));
  </code></pre>