snipt

Ctrl+h for KB shortcuts

Java

Get selection of list in ListActivity

ListView listview = (ListView)findViewById(android.R.id.list);
String sSel = listview.getSelectedItem().toString();
https://snippets.siftie.com/embed/b7bd24213c4559dd5dce38ecd9cb1a1e/
/raw/b7bd24213c4559dd5dce38ecd9cb1a1e/
b7bd24213c4559dd5dce38ecd9cb1a1e
java
Java
3
2019-03-15T15:37:19
True
False
False
/api/public/snipt/13969/
get-selection-of-list-in-listactivity
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">ListView</span> <span class="n">listview</span> <span class="o">=</span> <span class="o">(</span><span class="n">ListView</span><span class="o">)</span><span class="n">findViewById</span><span class="o">(</span><span class="n">android</span><span class="o">.</span><span class="na">R</span><span class="o">.</span><span class="na">id</span><span class="o">.</span><span class="na">list</span><span class="o">);</span> </span><span id="L-2"><a name="L-2"></a><span class="n">String</span> <span class="n">sSel</span> <span class="o">=</span> <span class="n">listview</span><span class="o">.</span><span class="na">getSelectedItem</span><span class="o">().</span><span class="na">toString</span><span class="o">();</span> </span></pre></div> </td></tr></table>
android