How to save icons in a list in Android?

How to save icons in the list in android?

+3
source share
3 answers

I'm not sure I understand your question. If you need images in a ListView, you will need to define your own layout for your list items. You can put the ImageView in this layout and then in getView or newView / bindView (depending on which adapter class you are extending), you can change the ImageView to contain any graphic that suits you.

+1
source

Create a new file in /res/layout/demo.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
   <ImageView
       android:id="@+id/image"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@drawable/icon"/>
   <TextView
       android:id="@+id/os_name"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"/>
</LinearLayout>

In your class file -

public class MyListActivity extends ListActivity {
    public void onCreate(Bundle icicle) {
       super.onCreate(icicle);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.row, R.id.os_name, values);
    setListAdapter(adapter);
    }
}

In the list you will receive text with an image.

+1
source

Source: https://habr.com/ru/post/1724489/


All Articles