How to set onClickListener on a button in a ListView (Adapter using Reflection...)?
<p>I'm using some reflection to set up a <code>ListView</code> made up of custom views. One of the <code>HashMaps</code> that I'll be using with this <code>Adapter</code> has a button in it. I'm pretty sure I need to set the <code>onClickListener</code> on the button in the <code>getView</code> method, but I'm not sure how. </p>

<p>Here's the code for my <code>Adapter</code>: </p>

<pre><code>private class ViewAdapter extends BaseAdapter {

    private HashMap&lt;String, View&gt; mMap = new HashMap&lt;String, View&gt;();
    private String[] mKeys;


    private Context mContext;

    private ViewAdapter(Context context, HashMap&lt;String, View&gt; map) {
        mContext = context;
        mMap = map;
        mKeys = mMap.keySet().toArray(new String[map.size()]);          

    }


    @Override
    public int getCount() {
        return mMap.size();
    }

    @Override
    public Object getItem(int position) {
        return mKeys[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row;
        Object myObject = null;
        Class myViewClass = null;
        Constructor constructor = null;
        Method methodToExecute = null;
        String[] arguments = {mKeys[position]};
        try {

            myViewClass = mMap.get(mKeys[position]).getClass();

            //grab the constructor          
             constructor = mMap.get(mKeys[position]).getClass().getConstructor(Context.class);

            //instantiate a new object.
            myObject = (View) constructor.newInstance(getBaseContext());



            //Grab the display method
            methodToExecute = myViewClass.getMethod("display", new Class[] {String.class});
            Log.i("method", methodToExecute.toString());


            } catch (Exception e) {
                e.printStackTrace();
            }

        if(convertView == null)  {

            row = (View) myObject;

        } else {
            row =  convertView;
        }

        try {
        methodToExecute.invoke(row, new Object[]{arguments});
        } catch (Exception e) {
            e.printStackTrace(); 
    }       
        return row;
    }

}
</code></pre>

<p>EDIT - Yeah, this was a ridiculous design decision. I ended up scrapping the whole thing and just going for a regular ArrayList of some ADT I created which had a field of a <code>Class</code> that I could set to be my particular custom <code>View</code> class. You live and you learn ;)</p>
