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;
        }
    }
  • 相关阅读:
    SpringBoot标准化搭建
    springboot打开swagger文档遇到For input string: ""的报错 swagger版本2.9.2
    MySQL和Redis如何保证数据一致性? 三种方案对比,初版
    [转]QUdpSocket收发信息
    [原][C++][插件]window下C++简单插件机制实现
    php saas 架构设计,SaaS的几种架构解析
    如何处理将HTML打印出来中的断行,分页,修改打印内容等问题?急,谢谢!!
    批量打印 | 多页打印 | PHP多页打印
    web页面的单页打印以及批量打印实现方法
    php批量打印发票三(php用FPDF合并所有图片为PDF文档)
  • 原文地址:https://www.cnblogs.com/abelsu/p/4661459.html
Copyright © 2011-2022 走看看