How to make an onClick method for each ListView item
<p>I have a listView, it has about 100 items.</p>

<p>Currently I have this code:</p>

<pre><code>public class VanillaList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vanilla_block_list);

        ArrayList&lt;ItemDetails&gt; image_details = GetSearchResults();

        final ListView lv1 = (ListView) findViewById(R.id.listV_main);
        lv1.setAdapter(new ItemListBaseAdapter(this, image_details));

        lv1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { 
                Object o = lv1.getItemAtPosition(position);
                ItemDetails obj_itemDetails = (ItemDetails)o;
                Toast.makeText(VanillaList.this, "You have clicked on : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
            }  
        });
    }
</code></pre>

<p>This shows a toast notification saying the name of the list item with "You have clicked on:" in front of it.</p>

<p>This is the case for all 100 items. How would I make a different onClick method for each item. I have tried:</p>

<pre><code>public class VanillaBlockList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vanilla_block_list);

        ArrayList&lt;ItemDetails&gt; image_details = GetSearchResults();

        final ListView lv1 = (ListView) findViewById(R.id.listV_main);
        lv1.setAdapter(new ItemListBaseAdapter(this, image_details));

        lv1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { 
                Object o = lv1.getItemAtPosition(position);
                ItemDetails obj_itemDetails = (ItemDetails)o;
                Toast.makeText(VanillaBlockList.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
            }  
lv2.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) { 
                Object o = lv2.getItemAtPosition(position);
                ItemDetails obj_itemDetails = (ItemDetails)o;
                Toast.makeText(VanillaBlockList.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
            } 
        });
    }
</code></pre>

<p>But this hasn't worked for me. Can anyone help me?
I would prefer an onClick method, like in the layout XML file there is <code>android:onClick="something"</code></p>

<p>Then in the java file:</p>

<pre><code>public void something{
//method here
}
</code></pre>

<p>Thanks.</p>
