0

I am using the custome view class below and I want to change the ImageView icon when someone selects a view in my list in onListItemClick. How do I get the view? In my OnCreate, I have

    iconicAdapter = new IconicAdapter();
    setListAdapter(iconicAdapter);

Then in my custom view class, I have

class IconicAdapter extends ArrayAdapter {
IconicAdapter() {
    super(myApp.this, R.layout.row, title_list);
}

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater=getLayoutInflater();
    View row=inflater.inflate(R.layout.row, parent, false);
    TextView title=(TextView)row.findViewById(R.id.list_title);
    title.setText(title_list.get(position).toString());
    ImageView icon=(ImageView)row.findViewById(R.id.icon);
    return(row);
}

}

What do I need in the method below to access the correct ImageView icon in my custom view class? Or should I access it a different way?

public void onListItemClick(ListView parent, View v, int position, long id) {
}

1 Answer 1

1

do the following:

public void onListItemClick(ListView parent, View v, int position, long id) {
    ((ImageView)v.findViewById(R.id.icon)).setImageBitmap(anyBitmap); 
    //((YourCustomAdapter)getListAdapter()).notifyDataSetChanged();
    //or
    //v.invalidate();
}

later you can set any resource to your image view, bitmap, drawable, etc.

cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.