• 列表视图


    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

  • 相关阅读:
    mui的相关知识
    4. 本地的json格式调用方法
    DOM树节点的相关知识
    3.函数引用中“值传参”与“引用传参”的区别
    一,数组的创建 数组的遍历
    重载<<
    SendMessage、PostMessage、PeekMessage、GetMessage、PreTreslateMessage等
    TranslateMessage
    怎样在整个类中恒定常量
    格式化输出
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5504096.html
Copyright © 2020-2023  润新知