Search code examples
androidlistviewtextviewdrawable

TextView change DrawableLeft in ListView


I have ArrayList which is load simple xml textview as item. In the TextView i have drawableleft, but i can`t figure it out, how to change that image? in adapter or? because there is now way out to insert drawable object in string list.

i have load items like:

items = new ArrayList<String>();
items.add(Some String item);

this is the adapter

ArrayAdapter<String> List = new ArrayAdapter<String>(this, R.layout.item_text, items);
ListView mylist = (ListView) findViewById(android.R.id.list);
mylist.setAdapter(List);

and my TextView item

<TextView
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="@drawable/folder"
android:drawableEnd="@drawable/next" >
</TextView>

Solution

  • Extend the ArrayAdapter class and override the getView() method. This method returns the View that will be placed in each row while the data is loaded. Use it to change the image as you wish.