简体   繁体   中英

how to change image in imageview from adapter android

How can i change image from adapter. I have created a ListView and in this listview i have added dynamic item which has name and picture. I want to change the pic from that item on some logic.

adapter is created by below code

SimpleAdapter adapter = new SimpleAdapter(this, menuItems , R.layout.list_item, new String[] { NAME, EMPID  }, new int[] { R.id.name, R.id.empid });
    setListAdapter(adapter);
    ListView lv = getListView();

below Code works fine if under OnItemClickListener. but i want image in at the time of rendering first view.

lv.setOnItemClickListener( new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
if(XMLUtil.getNodeValue(group, "Gender").equalsIgnoreCase("male")){
                    view.findViewById(R.id.imageView).setBackgroundResource(R.drawable.male);
                }else{
                    view.findViewById(R.id.imageView).setBackgroundResource(R.drawable.female);
                }
}

menuItems设置新图像并调用adapter.notifyDataSetChanged()以更新您的ListView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM