Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't have to add a new listener every time you add an element to the list. You can use a <code>OnItemClickListener</code> set once and for all, and you will be able to find the item that has been clicked by the index in the callback function </p> <pre><code>public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) </code></pre> <p>which is, parameter <code>int position</code>.</p> <p>Inside onItemClick implementation, you can then retrieve the element which has been clicked by</p> <pre><code>arg0.getItemAtPosition(position) </code></pre> <p>Also, you don't have to add the onItemClickListener every time, you can just prepare it once in the onCreate method of your Activity and never change it.</p> <p>What you will need to do instead, is making a new adapter (or adding a new item to the adapter) when your new file recording has terminated.</p> <p>I prepared an almost full sample to show how to use the ListView:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ArrayList&lt;String&gt; fileNames = new ArrayList&lt;String&gt;(); fileNames.add("Test1.mp3"); fileNames.add("Test2.mp3"); final ListView listView = (ListView) findViewById (R.id.mainListView); ArrayAdapter&lt;String&gt; listAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, fileNames); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { Toast toast = Toast.makeText(getApplicationContext(), (String)arg0.getItemAtPosition(position), Toast.LENGTH_SHORT); toast.show(); } }); } </code></pre> <p>This is enough if the items in the list do not change.</p> <p>When a recording of your next mp3 file terminates, and you want to add an item to the list, you may just do:</p> <pre><code>ListView listView = (ListView) findViewById (R.id.mainListView); fileNames.add("Test3.mp3"); ((ArrayAdapter&lt;String&gt;)listView.getAdapter()).notifyDataSetChanged(); </code></pre> <p>Replace "Test3" with your new recorded mp3's filename, and it will show up in the list.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload