0

I have a list view, containing different kinds of cells and I use an ArrayAdapter to do so.

private class MyAdapter extends ArrayAdapter<String>
{   
    public MyAdapter(Context context, int resource, int textViewResourceId, String[] objects)
    {
        super(context, resource, textViewResourceId, objects);
    }

    @Override
    public View getView(int position, View view, ViewGroup parent)
    {
        View viewCE = inflater.inflate(R.layout.my_cell, parent, false);
        ((TextView) viewCE.findViewById(R.id.txt_cell)).setText(adapter.getItem(position));
        view = viewCE;
        return view;
    }
}

my_cell contains an ImageView, and what I want to do is to change the image of this ImageView when the user clicks the cell.

I already added to my code a private class implementing OnItemClickListener with its method onItemClick() but then I've absolutely no idea of what to do...

Thanks for your help.

4

2 回答 2

2

in onItemCLick callback, the parameter view is exactly the view that contains your imageView, so you can find it by id then change it, sample codes are as below:

list.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
        ImageView image = ((ImageView) viewCE.findViewById(R.id.your_image_id));
        //do something by yourself
    }
}
于 2013-07-10T10:26:45.093 回答
0

If you want to handle the click event on the ImageView differently than the onClick of list item, you can add a seperate onClickListener to the Imageview like below:

imageView.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            // Change the image

        }

    });
于 2013-07-10T10:20:53.613 回答