android之arrayAdapter
来源:互联网 发布:淘宝人生 新笔趣阁 编辑:程序博客网 时间:2024/06/04 18:08
androidlayoutencodinglistviewhibernatestring
activity中代码:
- package com.ghg.ArrayAdapter;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class Day06_01_ArrayAdapterDemoActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- initView();
- }
- public String[] getData(){
- String[] arr={
- "xml","hibernate","spring","android","coreJava"
- };
- return arr;
- }
- ListView listView;
- private void initView() {
- // TODO Auto-generated method stub
- listView=(ListView) findViewById(R.id.lv_data);
- /** 1.创建数组适配器(四个参数)
- * this:环境,需要访问资源
- * R.layout.item1:确定在那个布局资源中显示
- * R.id.tv_data:确定显示在布局资源的的那个组件中
- * getData():提供显示的数据源
- */
- // 1. ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.item1, R.id.tv_data, getData());
- /**
- * 2.说明xml文件中布局结构是:<LinearLayout>
- * <TextView></TextView>
- * </LinearLayout>
- * 采用四个参数创建数组适配器可以正常显示;
- */
- // 2. ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.item2, R.id.tv_data, getData());
- /** 3.创建数组适配器(三个参数)
- * android.R.layout.simple_list_item_1:系统提供的布局;可以正常显示。
- * 但提出了一个问题?上面提供的布局是<LinearLayout>
- * <TextView></TextView>
- * </LinearLayout>
- * 还是直接就是一个<TextView></TextView>.
- * 在item3中证明 <TextView></TextView>布局可以正常显示;把item3的布局改成
- * <LinearLayout>
- * <TextView></TextView>
- * </LinearLayout>显示时抛出异常。
- */
- // 3. ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData());
- /** 通过自己定义的数组资源来创建数组适配器,并在item3上显示
- * R.array.words:自己定义的资源,在res/values/array.xml中;
- * R.layout.item3:把数组中的数据在这个控件上显示。
- */
- ArrayAdapter adapter=ArrayAdapter.createFromResource(this, R.array.words, R.layout.item3);
- listView.setAdapter(adapter);
- }
- }
main.xml如下:
- <?xml version="1.0" encoding="utf-8"?>
- <ListView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/lv_data"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- </ListView>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <ImageView
- android:layout_width="48dp"
- android:layout_height="48dp"
- android:src="@drawable/ic_launcher" />
- <TextView
- android:id="@+id/tv_data"
- android:layout_width="0dp"
- android:layout_height="48dp"
- android:layout_weight="1.0"
- android:gravity="center_vertical"
- />
- </LinearLayout>
item2.xml代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:id="@+id/tv_data"
- android:layout_width="0dp"
- android:layout_height="48dp"
- android:layout_weight="1.0"
- android:gravity="center_vertical"
- />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="48dp"
- android:textSize="20sp"
- >
- </TextView>
- android之arrayAdapter
- android之arrayAdapter
- Android之ArrayAdapter
- Android适配器之ArrayAdapter
- android之【ArrayAdapter】
- Android适配器之 ArrayAdapter
- Android学习之ArrayAdapter
- android适配器之ArrayAdapter
- android之ArrayAdapter使用
- Android之ArrayAdapter详解
- Android 之ArrayAdapter
- android之ArrayAdapter的重写
- Android之ListView详解ArrayAdapter
- Android之ArrayAdapter用法总结
- Android之自定义 ArrayAdapter适配器
- Android之ArrayAdapter的详解
- Android之ArrayAdapter实例(demo)
- android listview组件之ArrayAdapter,SimpleAdapter
- 《 BCG 原创 :系列 一》 BCGControlBar 的安装
- 加扰与加密的区别
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
- 银行务业调度系统之学习总结
- 《 BCG 原创 :系列 二》 基本设置:将MFC项目 修改 成为BCG 项目
- android之arrayAdapter
- HTML页面reLoad()
- [linux]深度软件中心无法下载软件的临时解决办法
- BCGControlBar 库 使用方法
- POJ 2362(Square-搜索剪枝1-相对顺序)
- hibernate分页
- 简易shell脚本提示Tomcat没有在正确的用户下启动。
- [Go] --- 控制结构
- android之SimpleAdapter创建和动态添加.删除SimpleAdapter选中项