博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArrayAdapter,SimpleAdapter
阅读量:6542 次
发布时间:2019-06-24

本文共 5571 字,大约阅读时间需要 18 分钟。

1--ArrayAdapter   ListViewActivity.java
package com.example.lenovo.textapp4;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;public class ListViewActivity extends AppCompatActivity {    ListView lv_1;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_list_view);        ListView lv_1=(ListView)findViewById(R.id.lv_1);        //1-数据集合   Layout文件        String []str={"A1","A2","A3","A4","A5","A6","A7","A8","A9","B1","B2","B3","B4","B5","B6","B7","B8","B9"};        //2-创建Adapter        ArrayAdapter
arrayAdapter=new ArrayAdapter
(this,R.layout.array_adapter,str); //3-绑定到ListView lv_1.setAdapter(arrayAdapter); }}
View Code

 

  activity_list_view.xml

View Code

 

  array_adapter.xml

View Code

 

 

 

2--SimpleAdapter

 

  List2Activity.java

package com.example.lenovo.textapp4;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.Hashtable;import java.util.List;import java.util.Map;import java.util.Objects;public class List2Activity extends AppCompatActivity {    ListView lv_2;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_list2);        lv_2=(ListView)findViewById(R.id.lv_2);        //1-数据集合   Layout文件        List
> lm=new ArrayList
>(); Map
map=new HashMap
(); map.put("img",R.drawable.f1); map.put("name","美食1"); map.put("content","美食1的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f2); map.put("name", "美食2"); map.put("content","美食2的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f3); map.put("name", "美食3"); map.put("content","美食3的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f4); map.put("name", "美食4"); map.put("content","美食4的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f5); map.put("name", "美食5"); map.put("content","美食5的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f6); map.put("name", "美食6"); map.put("content","美食6的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f7); map.put("name", "美食7"); map.put("content","美食7的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f8); map.put("name", "美食8"); map.put("content","美食8的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f9); map.put("name", "美食9"); map.put("content","美食9的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f10); map.put("name", "美食10"); map.put("content","美食10的美食介绍"); lm.add(map); //数组 key的数组 String [] strings={"img","name","content"}; int [] ids={R.id.iv_2,R.id.tv_7,R.id.tv_8}; //2-创建simpleadapter SimpleAdapter simpleAdapter=new SimpleAdapter(this,lm,R.layout.simpleadapter_activity,strings,ids); //绑定 lv_2.setAdapter(simpleAdapter); }}package com.example.lenovo.textapp4;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.Hashtable;import java.util.List;import java.util.Map;import java.util.Objects;public class List2Activity extends AppCompatActivity { ListView lv_2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list2); lv_2=(ListView)findViewById(R.id.lv_2); //1-数据集合 Layout文件 List
> lm=new ArrayList
>(); Map
map=new HashMap
(); map.put("img",R.drawable.f1); map.put("name","美食1"); map.put("content","美食1的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f2); map.put("name", "美食2"); map.put("content","美食2的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f3); map.put("name", "美食3"); map.put("content","美食3的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f4); map.put("name", "美食4"); map.put("content","美食4的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f5); map.put("name", "美食5"); map.put("content","美食5的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f6); map.put("name", "美食6"); map.put("content","美食6的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f7); map.put("name", "美食7"); map.put("content","美食7的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f8); map.put("name", "美食8"); map.put("content","美食8的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f9); map.put("name", "美食9"); map.put("content","美食9的美食介绍"); lm.add(map); map=new HashMap
(); map.put("img",R.drawable.f10); map.put("name", "美食10"); map.put("content","美食10的美食介绍"); lm.add(map); //数组 key的数组 String [] strings={"img","name","content"}; int [] ids={R.id.iv_2,R.id.tv_7,R.id.tv_8}; //2-创建simpleadapter SimpleAdapter simpleAdapter=new SimpleAdapter(this,lm,R.layout.simpleadapter_activity,strings,ids); //绑定 lv_2.setAdapter(simpleAdapter); }}
View Code

 

  activity_list2.xml

View Code

 

  simpleadapter_activity.xml

View Code

 

 

 

转载于:https://www.cnblogs.com/1ming/p/5502191.html

你可能感兴趣的文章
pandas Dataframe 取某行
查看>>
BZOJ 2599: [IOI2011]Race 点分治
查看>>
接口抽象类区别
查看>>
queue 队列
查看>>
前端之JavaScript--基础
查看>>
TCP/IP TIME_WAIT状态原理
查看>>
统计数中二进制表达式中1的个数
查看>>
陶哲轩实分析 定义7.11(有限级数) 注
查看>>
20145222黄亚奇《网络对抗》信息收集和漏洞扫描技术
查看>>
Windows API 第二篇 SHGetSpecialFolderPath
查看>>
关于成员变量和局部变量是否都会被默认初始化的问题
查看>>
安卓中实现界面数据懒加载
查看>>
linux命令之ls命令的简明讲解
查看>>
django基础知识~ RBAC权限周边初探
查看>>
Integer ,==,int 的使用
查看>>
数字图像处理中所用数学工具3---算术操作处理图像
查看>>
VUE JS 使用组件实现双向绑定
查看>>
减少页面加载时间的方法?
查看>>
未在本地计算机上注册microsoft.jet
查看>>
Restrictions.like() 模糊查询,以及使用DetachedCriteria查询的一般用法
查看>>