0

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.

1 Answer 1

1

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.

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.