zoukankan      html  css  js  c++  java
  • 列表视图

    package com.hanqi.testapp22;
    
    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 TestActivity8 extends AppCompatActivity {
    ListView lv_1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test8);
            lv_1=(ListView)findViewById(R.id.lv_1);
            List<Map<String,Object>> lm=new ArrayList<Map<String,Object>>();
            Map<String,Object> map=new HashMap<String, Object>();
            map.put("img",R.drawable.f1);
            map.put("name","美食1");
            map.put("content", "美食1的内容");
            lm.add(map);
    
             map=new HashMap<String, Object>();
            map.put("img", R.drawable.f2);
            map.put("name", "美食2");
            map.put("content", "美食的内容");
            lm.add(map);
    
             map=new HashMap<String, Object>();
            map.put("img",R.drawable.f3);
            map.put("name","美食3");
            map.put("content", "美食3的内容");
            lm.add(map);
            map=new HashMap<String, Object>();
            map.put("img",R.drawable.f4);
            map.put("name","美食4");
            map.put("content","美食4的内容");
            lm.add(map);
            map=new HashMap<String, Object>();
            map.put("img",R.drawable.f5);
            map.put("name","美食5");
            map.put("content","美食5的内容");
            lm.add(map);
            map=new HashMap<String, Object>();
            map.put("img",R.drawable.f6);
            map.put("name","美食6");
            map.put("content","美食6的内容");
            lm.add(map);
            map=new HashMap<String, Object>();
            map.put("img",R.drawable.f7);
            map.put("name","美食7");
            map.put("content","美食7的内容");
            lm.add(map);
            map=new HashMap<String, Object>();
            map.put("img",R.drawable.f8);
            map.put("name","美食8");
            map.put("content","美食8的内容");
            lm.add(map);
            String[] strings={"img","name","content"};
            int [] ids={R.id.iv_1,R.id.tv_1,R.id.tv_2};
            SimpleAdapter simpleadapter=new SimpleAdapter(this,lm,
                    R.layout.simple_adapter,strings,ids);
            lv_1.setAdapter(simpleadapter);
        }
    }
    <?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="match_parent">
        <ImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/f1"
            android:id="@+id/iv_1"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:gravity="center_vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="名字=aaa"
                android:id="@+id/tv_1"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="内容=aaa"
                android:id="@+id/tv_2"/>
    
        </LinearLayout>
    
    </LinearLayout>
    View Code

  • 相关阅读:
    lua 5.3最简单plugin编写
    CMake for MFC example
    写了个自动生成vcxproj的程序
    kindle試玩
    解放双手:如何在本地调试远程服务器上的Node代码
    PM2实用入门指南
    Express使用手记:核心入门
    Node服务一键离线部署
    fis-receiver:一行命令将项目部署到远程服务器
    Reflux系列01:异步操作经验小结
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5504096.html
Copyright © 2011-2022 走看看