微信通讯录静态页面

activity_main.xml

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

    <ImageView
        android:id="@+id/img"
        android:layout_margin="5dp"
        android:layout_width="35dp"
        android:layout_height="35dp"/>

    <TextView
        android:id="@+id/tv"
        android:textSize="20sp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

list_view.xml

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

    <ListView
        android:id="@+id/listview"
        android:divider="@drawable/c"
        android:dividerHeight="2dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

Mainactivity.java

package com.example.myapplication;


import androidx.appcompat.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 {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);
        //根据id找到ListView
        ListView listView=findViewById(R.id.listview);
        //数据
        //定义分组
        String[] group={"我的好友"};
        String[] type=new String[]{"新的朋友","群聊","标签","公众号","傻龙","熊美腻","宝贝婷","黄小田","宝藏晴","珍妮Jan","彤彤"};
        //图片路径
        int[] imgId = new int[] {R.mipmap.b,R.mipmap.b,
                R.mipmap.b,R.mipmap.b,
                R.mipmap.b,R.mipmap.b,
                R.mipmap.b,R.mipmap.b,
                R.mipmap.b,R.mipmap.b,
                R.mipmap.b};
        //将数组数据转换到list数据,泛型Map映射
        List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
        for (int i=0;i<type.length;i++){
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("img",imgId[i]);
            map.put("name",type[i]);
            list.add(map);
        }
        //适配器
        SimpleAdapter adapter=new SimpleAdapter(this,list,
                R.layout.activity_main,new String[]{"img","name"},
                new int[]{R.id.img,R.id.tv});
        //给列表视图设置适配器
        listView.setAdapter(adapter);
    }
}

//自己注意一下图片路径就好了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值