zoukankan      html  css  js  c++  java
  • 图文列表,关于Simpleadapter

    main.xml:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <ListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></ListView>
    </RelativeLayout>

    su.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="60dp"
    
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="8dp"
    
            />
        <LinearLayout
            android:layout_toRightOf="@+id/img"
            android:layout_width="match_parent"
            android:layout_height="60dp"
    
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="20dp"
    
    
                android:textSize="16sp"
                />
            <TextView
                android:id="@+id/info"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="20dp"
    
    
                android:textSize="10sp"/>
    
        </LinearLayout>
    
    </LinearLayout>

    MainActivity.java:

    public class MainActivity extends Activity {
        private ListView lv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            lv = (ListView)findViewById(R.id.listview);
            SimpleAdapter adapter = new SimpleAdapter(this,getData(),
                    R.layout.su,
                    new String[] {"img","title","info"},
                    new int[] {R.id.img,R.id.title,R.id.info});
            lv.setAdapter(adapter);
        }
    
        private List<Map<String,Object>> getData(){
            List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1802);
            map.put("title","Smith");
            map.put("info", "电台DJ");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1804);
            map.put("title","西施");
            map.put("info", "四大美女之一");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1805);
            map.put("title","大圣归来");
            map.put("info", "国产电影");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1809);
            map.put("title","旗木卡卡西");
            map.put("info", "copy忍者");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1810);
            map.put("title","飞雷神之术");
            map.put("info", "来无影去无踪");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1811);
            map.put("title","HelloKitty");
            map.put("info", "女生的最爱");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1816);
            map.put("title","机械暴龙兽");
            map.put("info", "亚古兽的完全体");
            list.add(map);
    
            map = new HashMap<String,Object>();
            map.put("img",R.drawable.s1811);
            map.put("title","HelloKitty");
            map.put("info", "女生的最爱");
            list.add(map);
    
            return list;
        }
    }
  • 相关阅读:
    云架构系统如何做性能分析?| 实战干货
    1024 程序员日,聊聊升职加薪与职业发展!
    测试面试题集锦(三)| 计算机网络和数据库篇(附答案)
    在线沙龙 | 前端测试技术创新与实践
    测试开发系列课程学员打卡听课细则
    这 5 款实用性能测试工具,你会如何选择?
    618 年中大促!Python 自动化测试训练营立减 1000 元!送接口测试实战课!
    美人
    栀子花开
    朋友别哭
  • 原文地址:https://www.cnblogs.com/abelsu/p/4661459.html
Copyright © 2011-2022 走看看