Gridview表格控件

效果图:

分析:

使用和ListvVew很像,都是经过适配器将数据绑定到控件上

具体步骤如下:

1、创建GridView控件,并指定列数

  android:numColumns="3"

2、创建显示数据项的数据容器,是一个Lauout文件,里面一个ImageView,一个TextView

  上面是ImageView,“小白10”是TextView显示的

3、创建好数据,这里用List来实现

  private List<HashMap<String, Object>> mData;

  mData=new ArrayList<HashMap<String,Object>>();

  然后是创建HashMap

    HashMap<String, Object> map=new HashMap<String, Object>();

       map.put("txt", "小白"+i);   

    map.put("image", images[i]);

    mData.add(map);

4、创建数据适配器,并且将数据绑定到数据适配器

  private SimpleAdapter adapter;

  adapter=new SimpleAdapter(this, mData, R.layout.itemview1,new String[]{"txt","image"}, new int[]{R.id.textView1,R.id.iv_avator});

5、为GridView设置数据适配器

  gridview.setAdapter(adapter);

代码:

fry.Activity01

 package fry;

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.example.gridView.R; import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter; public class Activity01 extends Activity{
private List<HashMap<String, Object>> mData;
private GridView gridview;
private SimpleAdapter adapter;
private int[] images=new int[]{
R.drawable.image1,R.drawable.image2,R.drawable.image3,
R.drawable.image5,R.drawable.image6,R.drawable.image7,
R.drawable.image8,R.drawable.image9,R.drawable.image10,
R.drawable.image11,R.drawable.image12,R.drawable.image13,
R.drawable.image14,R.drawable.image4
}; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01);
gridview=(GridView) findViewById(R.id.gridView1); mData=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<images.length;i++){
HashMap<String, Object> map=new HashMap<String, Object>();
map.put("txt", "小白"+i);
map.put("image", images[i]);
mData.add(map);
} adapter=new SimpleAdapter(this, mData, R.layout.itemview1,
new String[]{"txt","image"}, new int[]{R.id.textView1,R.id.iv_avator}); gridview.setAdapter(adapter);
}
}

主界面

/gridView/res/layout/activity01.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
></GridView> </LinearLayout>

创建GridView控件

/gridView/res/layout/itemview1.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" > <ImageView
android:id="@+id/iv_avator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image1" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小白"
/> </LinearLayout>

创建数据项容器

Gridview表格控件的更多相关文章

  1. 使用 Bolt 实现 GridView 表格控件

    用 Bolt 实现了一个表格控件: 1. 提供 Insert,Remove,Get,Set 接口,可以为表格增删数据: 2. 通过  ItemClass, ItemSetDataFunc 属性来指定显 ...

  2. Android入门之GridView(表格控件)

    GridView是一个表格控件,可以在每个单元格中显示自定义的View或者字符串.在这里我们要实现一个图标下方有文字的效果. 1.首先我们应自定义布局文件image_text.xml.代码如下: &l ...

  3. 深入浅出ExtJS 第三章 表格控件

    3.1 表格的特性简介 >.Ext中的表格功能:包括排序/缓存/拖动/隐藏某一列/自动显示行号/列汇总/单元格编辑等实用功能; >.表格由类Ext.grid.GridPanel定义,继承自 ...

  4. 动态生成表格呈现还是将表格直接绑定gridview等控件呈现的开发方式选择依据

    动态生成表格呈现还是将表格直接绑定gridview等控件呈现的开发方式选择依据:由存储过程决定,如果编写的存储过程可以生成需要呈现的表格则直接绑定,否则要动态生成表格

  5. C# DatrgridView表格控件的一些用法

    public class useDatrgrivView { string conn = null; string sqlComm = null; DataSet das = null; DataGr ...

  6. 在GridControl表格控件中实现多层级主从表数据的展示

    在一些应用场景中,我们需要实现多层级的数据表格显示,如常规的二级主从表数据展示,甚至也有多个层级展示的需求,那么我们如何通过DevExpress的GridControl控表格件实现这种业务需求呢?本篇 ...

  7. 如何在web中实现类似excel的表格控件

    Execl功能非常强大,内置的很多函数或公式可以大大提高对数据的加工处理能力.那么在web中有没有类似的控件呢?经过一番搜寻,发现handsontable具备了基本的excel功能支持公式,同时能对数 ...

  8. 最好的Angular2表格控件

    现在市面上有大量的JavaScript数据表格控件,包括开源的第三方的和自产自销的.可以说Wijmo的Flexgrid是目前适应Angular 2的最好的表格控件. Angular 2数据表格基本要求 ...

  9. 类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内。

    错误的写法:  if (this.GridView1.Rows.Count > 0)         {             string style = @"<style& ...

随机推荐

  1. 玩转公众号markdown排版

    Md2All 简介 Markdown排版利器,支持 "一键排版" 的样式模板选择,支持"css样式自定义",支持80多种代码高亮. 能让Markdown内容,无 ...

  2. windows和linux无法访问VMware中linux的tomcat主页问题

    1.一定确定自己的tomcat服务器是启动的.(为了确保保险可以在测试前重新shutdown,startup一次) 2.确定自己访问的ip地址和端口号是正确的 如果是VMware外部windows的话 ...

  3. php数据库增删改查

    首先建立一个数据库db_0808,将db_0808中表格student导入网页. CURD.php <!DOCTYPE html> <html lang="en" ...

  4. ArrayList 源码

    1.ArrayList的类关系: 2.属性及方法      2.1 构造           三个构造方法分别对应:                通过传入初始化容器大小构造数组列表         ...

  5. C# Socket通讯 本机多网卡,指定网卡通讯

    IPAddress ip = IPAddress.Parse("192.168.0.188"); IPAddress IPLocal = IPAddress.Parse(" ...

  6. 《Java编程思想》学习笔记(一)

    1——面向对象和JVM基础  1.java中的4种访问制权限: (1).public:最大访问控制权限,对所有的类都可见. (2).protect:同一包可见,不在同一个包的所有子类也可见. (3). ...

  7. webSphere

    WebSphere 是 IBM 的软件平台.它包含了编写.运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台.跨产品解决方案所需要的整个中间件基础设施,如服务器.服务和工具.WebSphe ...

  8. Windows上使用iverilog+gtkwave仿真

    主要参考了: https://www.cnblogs.com/lsgxeva/p/8280662.html 谢谢! ------------------------------------------ ...

  9. [接口管理平台] eoLinker AMS 专业版 V3.5 :加入数据结构管理、通用函数管理、API 快速测试等近 30 项更新

    eoLinker AMS是集API文档管理.API自动化测试.开发协作三位一体的综合API开发管理平台,是中国最大的在线API管理平台.目前eoLinker AMS已经为来自全球的超过两万家企业托管超 ...

  10. mint-ui 取值

    //slots:[{values: ['年假', '事假', '病假', '婚假', '其他']}], slots:[{values: []}], onValuesChange(picker,valu ...