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封装类 的文章,主要存在几个问题: 一).网上代码一大抄,复制来复制去,大部分都运行不起来,或者 格 ...
随机推荐
- 对比react和vue
相同点 都有组件化开发和virtual DOM(具体实现方式不同) 都支持props进行父子组件间数据通信 都支持数据驱动,不直接操作真实DOM,更新状态数据,界面自动更新 都支持服务器渲染 都支持n ...
- Educational Codeforces Round 2 E - Lomsat gelral
题意:每个节点有个值,求每个节点子树众数和 题解:可线段树合并,维护每个数出现次数和最大出现次数,以及最大出现次数的数的和 //#pragma GCC optimize(2) //#pragma GC ...
- python中for循环的底层实现机制 迭代
在python中,存在2种循环方式:for循环和while循环. while循环的实现很简单, 其本质就是一个条件语句,自定义条件,当条件满足的时候,不断执行while代码块. 但是for循环,究竟是 ...
- java中equals与==的比较
总结来说: 1)对于==,如果作用于基本数据类型的变量,则直接比较其存储的 “值”是否相等: 如果作用于引用类型的变量,则比较的是所指向的对象的地址 2)对于equals方法,注意:equals方法不 ...
- CRM WEB UI 03搜索界面新建按钮调到详细界面
这个和上一个差不多,简单说下: 1.因为NEW是在创建搜索界面的时候加的,所以此时只需在结果界面重定义NEW事件: method EH_ONNEW. OP_NEW( ). endmethod. 2.结 ...
- 错误:this is incompatible with sql_mode=only_full_group_by
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'H5APP_WORK ...
- vue组件生命周期详解
Vue所有的生命周期钩子自动绑定在this上下文到实例中,因此你可以访问数据,对属性和方法进行运算.这意味着你不能使用箭头函数来定义一个生命周期方法.这是因为箭头函数绑定了父上下文,因此this与你期 ...
- Charles破解网站收藏(持续更新)
1. 在这个网站(http://charles.iiilab.com/)下载破解文件 charles.jar 2. 替换掉原文件夹里的charles.jar Mac: /Applications/Ch ...
- 【转】vue.js表单校验详解
官方文档:https://monterail.github.io/vuelidate/ https://github.com/monterail/vuelidate 1.npm安装vue-valida ...
- InnoDB支持的最大事务数量
Innodb存储引擎有rollback segment,每个rollback segment中记录了1024个undo log segment,在每个undo log segment中进行undo页的 ...