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.
精彩评论