Изображения, не отображаемые в ListView с помощью простого адаптера в моем приложении - PullRequest
0 голосов
/ 25 августа 2018

Я хочу сделать простой просмотр списка, имеющий 2 просмотра текста и один просмотр изображения.Textviews показывает правильный текст, но imageview показывает фон, который был установлен в XML-файле.

.java file: -

    String laptops[] = {"DELL Inspiron 15", "Mosiso smooth Matte Finish", "HP 
    455 ", "MicroMax 1160", "Asus Eeebook"};
                String keys[]={"name","price","image"};     //from array
                int price[]={20000,30000,23980,40000,28000};
                int images[]= 
{R.drawable.lap,R.drawable.lapt,R.drawable.lapt,R.drawable.lapto,R.drawable.laptop};
            int x=R.drawable.lapt;
            int[] to={R.id.textView3,R.id.textView4,R.id.imageView2};
            ArrayList<HashMap<String,String>> al=new ArrayList<HashMap<String, String>>();
            for(int i=0;i<5;i++)
            {
                HashMap<String,String> h=new HashMap<String, String>();
                h.put("name",laptops[i]);
                h.put("price",price[i]+" ");
                h.put("image",images[i]+" ");
                al.add(h);
            }
            ListView lv = (ListView) findViewById(R.id.list);
            SimpleAdapter sa=new SimpleAdapter(this,al,R.layout.new_manual,keys,to);
           lv.setAdapter(sa);
        }

new_manual - файл ресурсов, используемый для просмотра списка.

new_manual.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="33dp"
        android:layout_marginTop="92dp"
        android:text="TextView"
        android:layout_toLeftOf="@id/textView4"/>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignTop="@+id/textView3"
        android:layout_marginEnd="137dp"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginEnd="17dp"
        android:layout_marginTop="75dp"
        app:srcCompat="@mipmap/ic_launcher"
        android:background="@drawable/ic_launcher_background"/>
</RelativeLayout>

activity_main.xml: -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="16dp"
        android:divider="@color/Grey"
        android:dividerHeight="2dp"
        android:footerDividersEnabled="true"
        android:headerDividersEnabled="true"

        />

</RelativeLayout>

Вывод показывает это: - экран приложения

Я хочу изображения, указанные вмассив изображений вместо ic_launcher_background в просмотре списка.Заранее спасибо:)

1 Ответ

0 голосов
/ 25 августа 2018

Вы должны создать свой собственный ListAdapter для показа изображений, здесь вы можете найти хороший урок, как это сделать custom-listview

...