第六次作业

烈酒焚心 提交于 2019-12-04 01:22:14
package com.example.zuoye6;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
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 Activity{
private ListView listView;
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView lv = (ListView) findViewById(R.id.lv1);
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object>map = new HashMap<String,Object>();
        map.put("logo",R.drawable.jingdong);
        map.put("title","京东商城");
        map.put("version","版本:2.4.3");
        map.put("size","大小:78.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.doudizhu);
        map.put("title","QQ斗地主");
        map.put("version","版本:4.0.8");
        map.put("size","大小:134.7MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.liulanqi);
        map.put("title","UC浏览器");
        map.put("version","版本:3.8.5");
        map.put("size","大小:63.2MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.tianmao);
        map.put("title","天猫商城");
        map.put("version","版本:5.6.4");
        map.put("size","大小:88.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.xinlangweibo);
        map.put("title","新浪微博");
        map.put("version","版本:4.1.6");
        map.put("size","大小:89.6MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.weixin);
        map.put("title","微信");
        map.put("version","版本:6.0.3");
        map.put("size","大小:216.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.qq);
        map.put("title","QQ");
        map.put("version","版本:7.8.3");
        map.put("size","大小:178.3MB");
        list.add(map);

        SimpleAdapter adapter = new SimpleAdapter(
                this,
                list,R.layout.item,
                new String[]{"logo","title","version","size"},
                new int[]{R.id.logo,R.id.title,R.id.version,R.id.size}
        );
lv.setAdapter(adapter);
    }
}
package com.example.zuoye6;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
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 Activity{
private ListView listView;
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView lv = (ListView) findViewById(R.id.lv1);
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object>map = new HashMap<String,Object>();
        map.put("logo",R.drawable.jingdong);
        map.put("title","京东商城");
        map.put("version","版本:2.4.3");
        map.put("size","大小:78.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.doudizhu);
        map.put("title","QQ斗地主");
        map.put("version","版本:4.0.8");
        map.put("size","大小:134.7MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.liulanqi);
        map.put("title","UC浏览器");
        map.put("version","版本:3.8.5");
        map.put("size","大小:63.2MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.tianmao);
        map.put("title","天猫商城");
        map.put("version","版本:5.6.4");
        map.put("size","大小:88.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.xinlangweibo);
        map.put("title","新浪微博");
        map.put("version","版本:4.1.6");
        map.put("size","大小:89.6MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.weixin);
        map.put("title","微信");
        map.put("version","版本:6.0.3");
        map.put("size","大小:216.3MB");
        list.add(map);

        map = new HashMap<String,Object>();
        map.put("logo",R.drawable.qq);
        map.put("title","QQ");
        map.put("version","版本:7.8.3");
        map.put("size","大小:178.3MB");
        list.add(map);

        SimpleAdapter adapter = new SimpleAdapter(
                this,
                list,R.layout.item,
                new String[]{"logo","title","version","size"},
                new int[]{R.id.logo,R.id.title,R.id.version,R.id.size}
        );
lv.setAdapter(adapter);
    }
}
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/lv1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    </ListView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">



    <RelativeLayout
        android:id="@+id/box"
        android:background="#FCFDFC"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:padding="5dp"/>

<ImageView
    android:id="@+id/logo"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/jingdong"
    android:layout_centerVertical="true"/>


    <Button
        android:id="@+id/bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="安装"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        />


    <LinearLayout
        android:id="@+id/textbox"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_toRightOf="@+id/logo"
        android:layout_toLeftOf="@+id/bt1"
        android:layout_centerVertical="true"
        android:orientation="vertical"


        >
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dp"
            android:text="京东商城"
            android:textSize="16sp" />


        <TextView
            android:id="@+id/version"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="版本:2.4.3"
            android:textColor="#666666"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/size"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="大小:78.3MB"
            android:textColor="#666666"
            android:textSize="13sp" />


    </LinearLayout>

</RelativeLayout>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!