ListView-simpleAdapter

样式图+工程结构图

ListView-simpleAdapter_第1张图片 ListView-simpleAdapter_第2张图片

main-xml



item-xml




    
        
        
    


Acivity中代码

package com.example.listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity_simpleadapter extends AppCompatActivity {

    private ListView lv_main_show;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv_main_show = findViewById(R.id.lv_main_show);

        List> data = new ArrayList<>();
        Map mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f1);
        mapdate1.put("name", "name--1");
        mapdate1.put("price", "price--1");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f2);
        mapdate1.put("name", "name--2");
        mapdate1.put("price", "price--2");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f3);
        mapdate1.put("name", "name--3");
        mapdate1.put("price", "price--3");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f4);
        mapdate1.put("name", "name--4");
        mapdate1.put("price", "price--4");
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f5);
        mapdate1.put("name", "name--5");
        mapdate1.put("price", "price--5");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f6);
        mapdate1.put("name", "name--6");
        mapdate1.put("price", "price--6");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f7);
        mapdate1.put("name", "name--7");
        mapdate1.put("price", "price--7");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f8);
        mapdate1.put("name", "name--8");
        mapdate1.put("price", "price--8");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f9);
        mapdate1.put("name", "name--9");
        mapdate1.put("price", "price--9");
        data.add(mapdate1);
        mapdate1 = new HashMap<>();
        mapdate1.put("icon", R.drawable.f10);
        mapdate1.put("name", "name--10");
        mapdate1.put("price", "price--10");
        data.add(mapdate1);
        String[] from = {"icon", "name", "price"};
        int[] to = {R.id.iv_simple_icon, R.id.tv_simple_name, R.id.tv_simple_price};
        SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.simpleadapter_layout,from,to);
        lv_main_show.setAdapter(adapter);

    }
}

 

你可能感兴趣的:(安卓基础学习,android)