Android修行之路------ListView自定义布局
主布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@mipmap/bg_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/second_listview"
android:layout_width="match_parent"
android:layout_height="150dp"/>
</LinearLayout>
ListView布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/main_list_image"
style="@style/image" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/second_text_title"
style="@style/second_text_title" />
<TextView
android:id="@+id/second_text_text"
style="@style/second_text_text" />
</LinearLayout>
</LinearLayout>
主代码
package com.example.administrator.lin_android; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
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 page2_main extends AppCompatActivity {
//布局listview
String [] textTitle=new String[]{"ETC信息查询","停车场信息查询","公交站台信息监控","小车行驶路线控制","环境监控","红绿灯控制","路灯控制"};
String [] textText=new String[]{"查询ETC费率和各个时间点小车消费记录","查询停车场费率和各个时间点小车消费记录","查询公交车站台公交车信息","设置小车行驶路径","查询各个传感器数据信息","设置每个红绿灯状态和时间","设置每个路灯的开关和自动/手动模式"};
int [] image=new int[]{R.mipmap.ip,R.mipmap.sign,R.mipmap.register,R.mipmap.ip,R.mipmap.sign,R.mipmap.register,R.mipmap.ip};
ListView second_list; @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2_main); //布局
List<Map<String,Object>> data= new ArrayList<Map<String,Object>>();
for (int i=0;i<textText.length;i++)
{
HashMap<String,Object> map=new HashMap<String,Object>();
map.put("textTitle",textTitle[i]);
map.put("textText",textText[i]);
map.put("image",image[i]);
data.add(map);
} SimpleAdapter adt = new SimpleAdapter(this,data,R.layout.page2_main_list,
new String[]{"image","textTitle","textText"},
new int[]{R.id.main_list_image,R.id.second_text_title,R.id.second_text_text});
second_list=findViewById(R.id.second_listview);
second_list .setAdapter(adt);
}
}
Android修行之路------ListView自定义布局的更多相关文章
- Android修行之路------List view无法获取监听方法
注意: 1.在list view自定义布局中如果添加滚动布局,会导致自定义布局无法获取监听. 2.如果ListView的每项布局里有像Button,ImageButton之类View的控键时,这些Vi ...
- 我的Android开发之路——ListView的使用
在Android开发过程中,遇到需要列表显示的时候,这时候就会用到listview. 1.首先创建一个ListViewTest项目,选择empty activity类型.修改activity_main ...
- Android 中的AlertDialog使用自定义布局
Android使用指定的View开发弹窗功能 Android开发中进程会使用到我们的AlertDialog,但是比较可惜的是我们的Android原生的AlertDialog的效果又比较的简陋,这个时候 ...
- 【Android基础】listview控件的使用(4)-----自定义布局的listview的使用
前面我介绍了listview控件的不同用法,但是这些用法在实际的开发项目中是不足以满足需求的,因为前面的几种用法只能简单的显示文本信息,而且布局都比较单一,很难做出复杂的结果,在实际的开发项目中,90 ...
- Android开发学习之路--UI之自定义布局和控件
新的一年已经开始了,今天已经是初二了,两天没有学习了,还是要来继续学习下.一般手机的title都是actionbar,就像iphone一样可以后退,可以编辑.这里自定义布局就来实现下这个功能,首先准备 ...
- Android ListView 自定义 Adapter
自定义Adapter类 public class ListViewAdapter extends BaseAdapter { private static final String TAG = Mai ...
- android开发之路08(ListView&Adapter)
ListView控件介绍:用于将数据库中的数据或者网络中的数据通过列表的形式显示出来:ListView采用MVC模式将前端显示和后端数据进行分离. 也就是说,ListView控件在装载数据时并不是直接 ...
- Android:创建可穿戴应用 - 自定义布局
创建自定义布局(Creating Custom Layouts) 本文将介绍如何创建自定义通知以及使用可穿戴UI库来创建自定义布局你同时还需要了解可穿戴设计准则(Wear Design Princip ...
- [Android] Android RecycleView和ListView 自定义Adapter封装类
在网上查看了很多对应 Android RecycleView和ListView 自定义Adapter封装类 的文章,主要存在几个问题: 一).网上代码一大抄,复制来复制去,大部分都运行不起来,或者 格 ...
随机推荐
- php 递归删除文件夹
/*** 递归删除文件方法一 param $path 文件路径 **/ function delAll($path){ $path=str_replace('\\','/',$path);//去除反斜 ...
- New Year and Old Subsequence CodeForces - 750E (dp矩阵优化)
大意: 给定字符串, 每次询问区间[l,r]有子序列2017, 无子序列2016所需要删除的最小字符数 转移用矩阵优化一下, 要注意$(\mathbb{Z},min,+)$的幺元主对角线全0, 其余全 ...
- BigInteger 类 和 BigDecimal 类
一 .BigInteger BigInteger类在计算和处理任意大小的整数方面是很有用的. BigInteger 任意大的整数,原则上是,只要你的计算机的内存足够大,可以有无限位的. BigInte ...
- 『TensorFlow』分布式训练_其三_多机分布式
本节中的代码大量使用『TensorFlow』分布式训练_其一_逻辑梳理中介绍的概念,是成熟的多机分布式训练样例 一.基本概念 Cluster.Job.task概念:三者可以简单的看成是层次关系,tas ...
- Selenium-WebDriver驱动对照表
Chrome 对于chrome浏览器,有时候会有闪退的情况,也许是版本冲突的问题,我们要对照着这个表来对照查看是不是webdriver和chrome版本不对 chromedriver版本 支持的Chr ...
- 51nod1647 小Z的trie
题意:给你n个字符串,m次查询,每次问你第p个字符串的s到t的字符串在n个字符串建成的字典树上出现了多少次 题解:先建出字典树,在字典树上拓展sam,记录每个子串的出现次数.查询时只需找出在字典树上的 ...
- HDU-4587-tarjin/割点
http://acm.hdu.edu.cn/showproblem.php?pid=4587 给出一幅无向图,问除去两个点之后子图的最大联通分量个数. 考虑每次ban一个点然后跑一遍tarjin统计下 ...
- virtualbox 中centOS在不能ssh
这个重要跟虚拟机的网络设置有关系.废话不多说. 针对一个网卡的形式.可以如下进行配置 1.网络-- 连接方式还选择“网络地址转换(NAT)” 其他不变,展开高级,设置端口转发 主机IP设为本机IP, ...
- Cassandra标准列和超级列
列(column)是Cassandra数据模型中的最基本的数据结构单元.列是一个由列名(key).值(value).时间戳(timestamp)构成的三元组.在关系型数据库中,你需要先定义列的名称和和 ...
- CSS知识点(三)
十三.标准文档流. 标准文档流下有哪些微观现象? 1.空白折叠现象 多个空格会被合并成一个空格显示到浏览器页面中.img标签换行写.会发现每张图片之间有间隙,如果在一行内写img标签,就解决了这个问题 ...