zoukankan      html  css  js  c++  java
  • LisView

    界面布局

    *界面布局的编写

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/list"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title1"
                android:text="@string/app_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:id="@+id/title2"
                android:text="@string/nianli"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:id="@+id/title3"
                android:text="@string/dizhi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:id="@+id/title4"
                android:text="@string/youxiang"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
    

    java代码部分

    package com.example.zhoushasha.myapplication;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    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 MainActivity extends AppCompatActivity {
        private String[] name={"张学友","刘德华","黎明","郭富城","林志颖"};
        private int [] age={11,20,45,29,24};
        private String[] adress={"香港","广州","深圳","厦门","澳门"};
        private ListView list1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            List<Map<String, Object>> listems = new ArrayList<>();
            for (int i = 0; i < name.length; i++) {
                Map<String, Object> listem = new HashMap<>();
                listem.put("name", "姓名:"+name[i]);
                listem.put("age", "年龄:"+age[i]);
                listem.put("adress", "地址:"+adress[i]);
                listem.put("mail","邮箱:"+mail[i]);
                listems.add(listem);
            }
            SimpleAdapter simplead = new SimpleAdapter(this, listems,R.layout.activity_show, new String[] { "name", "age", "adress","mail" },
                    new int[] {R.id.name,R.id.age,R.id.adress,R.id.mail});
            list1=(ListView)findViewById(R.id.list1);
            list1.setAdapter(simplead);
        }
    }
    
  • 相关阅读:
    重建索引报错-python数据分析
    机器学习实战1-2.1 KNN改进约会网站的配对效果 datingTestSet2.txt 下载方法
    机器学习实战1-1 KNN电影分类遇到的问题
    权限掩码umask详解
    spark配置(7)--on yarn配置
    spark配置(6)-独立应用程序
    spark配置(5)-独立应用程序
    spark配置(4)-----Spark Streaming
    spark配置(3)
    spark配置(2)
  • 原文地址:https://www.cnblogs.com/YUESEtaimei/p/6798808.html
Copyright © 2011-2022 走看看