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;
        }
    }
  • 相关阅读:
    Django REST framework+Vue 打造生鲜超市(七)
    Django REST framework+Vue 打造生鲜超市(六)
    Django REST framework+Vue 打造生鲜超市(五)
    Django REST framework+Vue 打造生鲜超市(四)
    Django REST framework+Vue 打造生鲜超市(三)
    Django REST framework+Vue 打造生鲜超市(二)
    十分钟理解Java中的动态代理
    [020]Sencha Ext JS 6.0使用教程2
    ExtJS6的中sencha cmd中自动创建案例项目代码分析
    Sencha Cmd创建Ext JS示例项目
  • 原文地址:https://www.cnblogs.com/abelsu/p/4661459.html
Copyright © 2011-2022 走看看