1、添加GridItem布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" > <ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="60dp" android:src="@drawable/app" /> <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置中心" /> </LinearLayout>

2、主界面添加GridView

 <GridView
android:id="@+id/grid_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
> </GridView>

3、添加自定义适配器类,并对自定义griditem布局文件中的控件进行设置值

protected class MyGridAdapter extends BaseAdapter {

        @Override
public int getCount() {
// TODO Auto-generated method stub
return titles.length;
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = View.inflate(MainActivity.this, R.layout.list_item_main, null);
TextView title = (TextView) view.findViewById(R.id.tv_title);
title.setText(titles[position]); return view;
}

4、设置主界面中的GridItem

private GridView grid_main;
private MyGridAdapter adapter;
private static String []titles = {"设置中心1","设置中心2","设置中心3","设置中心4","设置中心5","设置中心6","设置中心7","设置中心8","设置中心9"}; ....
grid_main = (GridView) findViewById(R.id.grid_main);
adapter = new MyGridAdapter();
grid_main.setAdapter(adapter);

5、添加item点击事件

grid_main.setOnItemClickListener(new OnItemClickListener() {

            @Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
ConsoleItemClick(position);
}
});

6、显示

Android开发学习笔记-GridView的动态显示的更多相关文章

  1. android开发学习笔记000

    使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...

  2. android开发学习笔记系列(1)-android起航

    前言 在学习安卓的过程中,我觉得非常有必要将自己所学的东西进行整理,因为每每当我知道我应该是如何去实现功能的时候,有许多细节问题我总是会遗漏,因此我也萌生了写一系列博客来描述自己学习的路线,让我的an ...

  3. 【转】Android开发学习笔记(一)——初识Android

    对于一名程序员来说,“自顶向下”虽然是一种最普通不过的分析问题和解决问题的方式,但其却是简单且较为有效的一种.所以,将其应用到Android的学习中来,不至于将自己的冲动演变为一种盲目和不知所措. 根 ...

  4. Android开发学习笔记DDMS的使用

    打开DDMS DDMS 的全称是Dalvik Debug Monitor Service,是 Android 开发环境中的Dalvik虚拟机调试监控服务. DDMS里面包含了:Device(设备) F ...

  5. 【转】Android开发学习笔记:5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  6. 【Android开发学习笔记之一】5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  7. Android开发学习笔记(二)——编译和运行原理(1)

    http://www.cnblogs.com/Pickuper/archive/2011/06/14/2078969.html 接着上一篇的内容,继续从全局了解Android.在清楚了Android的 ...

  8. android开发学习笔记系列(2)-android应用界面编程

    前言 本篇博客将会简要介绍andriod开发过程中的一些界面元素和编程的实现,我将大家走进安卓的XML世界,当然可能会涉及到java代码,当然本文主要是介绍XML文件的界面布局. 那么我们的XML存在 ...

  9. Android开发学习笔记:浅谈GridView

    GridView(网格视图)是按照行列的方式来显示内容的,一般用于显示图片,图片等内容,比如实现九宫格图,用GridView是首选,也是最简单的.主要用于设置Adapter. GridView常用的X ...

随机推荐

  1. 《5天学会卡西欧fx-5800p之实操视频教程(初级)》目录和我的工作室现场曝光

    很多人给我讲,想让我录制一份卡西欧fx-5800p的视频教程,我也一直在准备,准备了半年,录制视频真的不是件容易的事,条件有限,而且工作也很忙,中途还会有想放弃的念头,真的是花费了我很多的心血,但不管 ...

  2. flume 多chanel配置

    #配置文 a1.sources= r1 a1.sinks= k1 k2 a1.channels= c1 c2 #Describe/configure the source a1.sources.r1. ...

  3. 【转】使用scipy进行层次聚类和k-means聚类

    scipy cluster库简介 scipy.cluster是scipy下的一个做聚类的package, 共包含了两类聚类方法: 1. 矢量量化(scipy.cluster.vq):支持vector ...

  4. 【嵌入式】——对#define GPBCON (*(volatile unsigned long*)0x56000010)的理解

    #define GPBCON (*(volatile unsigned long*)0x56000010) 1:volatile 当计算机需要一个数值的时候,会先把内存中的值读取到寄存器,然后下次在使 ...

  5. PHP 实战之设计模式:PHP 中的设计模式

    本文主要讨论下Web开发中,准确而言,是PHP开发中的相关的设计模式及其应用.有经验的开发者肯定对于设计模式非常熟悉,但是本文主要是针对那 些初级的开发者.首先我们要搞清楚到底什么是设计模式,设计模式 ...

  6. JQ 弹出层全屏

    下载:http://sc.chinaz.com/jiaoben/150427225380.htm http://sc.chinaz.com/jiaoben/150427225380.htm

  7. android开发 系统时间与定时器之间有关系嘛?

    如题: android开发 系统时间与定时器之间有关系嘛? 答案:有. 看定时器源码: /* * Schedule a task. */ private void scheduleImpl(Timer ...

  8. android studio 解析Excel数据格式导入poi-3.17.jar时的一系列报错及处理Failed resolution of: Ljavax/xml/stream/XMLEventFactory,duplicate entry: org/apache/xmlbeans/xml/stream/Location.class,GC overhead limit exceeded

    在org官网下载的poi jar包,导入到studio compile files('libs/poi-3.17.jar') compile files('libs/poi-ooxml-3.17.ja ...

  9. Coneroller执行时候的-26374及-26377错误

    有时候一些不必要的关联也会引起这个问题, 1.首先看下脚本中有没有使用了自动关联(web_reg_save_param) 2.在Virtual的脚本里查询下web_reg_save_param的参数使 ...

  10. Unity下Iso和Persp两种模式的区别

    Iso模式 平行视野.在Iso模式下,不论物体距离摄像头远近都给人的感觉是一样大的. Persp模式 透视视野.在persp模式下,物体在scene界面上所呈现的画面是给人一种距离摄像头近的物体显示的 ...