开发者

Need to change an ImageView in custom ArrayAdapter class

开发者 https://www.devze.com 2023-01-29 05:10 出处:网络
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

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 ti开发者_开发问答tle=(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) {
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消