开发者

Android Development: Change ImageView Source in A ListView

开发者 https://www.devze.com 2023-01-23 17:26 出处:网络
I\'m struggling to understand how I\'d go about changing an ImageView\'s src at runtime in a ListActivity.

I'm struggling to understand how I'd go about changing an ImageView's src at runtime in a ListActivity.

In a function I have this line which is where the custom file row is set for the ListView:

  setListAdapter(new ArrayAdapter<String>(this, R.layout.listrow, R.id.listtext,开发者_运维技巧 this.directoryEntries));

In listrow.xml, I have an ImageView which I would like to set the src as a folder image or a file image (for my file browser).

I don't set the content view to listrow.xml so I can't simple go:

ImageView img = (ImageView) findViewById(R.id.listicon); 
img.setImageResource(R.drawable.foldericon);

So how can I do it? Sorry if I'm not making much sense.


For an ArrayAdapter, you will need to make a subclass, override getView(), and replace your image there. Here is a free excerpt from one of my books that describes the techinques.

0

精彩评论

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

关注公众号