ArrayAdapter创建ListView学习笔记
来源:互联网 发布:手机 截gif软件 编辑:程序博客网 时间:2024/05/21 09:21
activity_main.xml总的布局文件、array_item.xml为list1的布局、checked_item.xml为list2的布局。
java代码:
super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ListView list1 = (ListView) findViewById(R.id.list1);// 定义一个数组String[] arr1 = { "孙悟空", "猪八戒", "牛魔王" };// 将数组包装ArrayAdapterArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.array_item, arr1);// 为ListView设置Adapterlist1.setAdapter(adapter1);ListView list2 = (ListView) findViewById(R.id.list2);// 定义一个数组String[] arr2 = { "Java", "Hibernate", "Spring" , "Android" };// 将数组包装ArrayAdapterArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, R.layout.checked_item, arr2);// 为ListView设置Adapterlist2.setAdapter(adapter2);}
activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><!-- 设置使用红色的分隔条 --><ListView android:id="@+id/list1"android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="#f00"android:dividerHeight="2px"android:headerDividersEnabled="false"/><!-- 设置使用绿色的分隔条 --><ListView android:id="@+id/list2"android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="#0f0"android:dividerHeight="2px"android:headerDividersEnabled="false"/></LinearLayout>
array_item.xml代码:
<?xml version="1.0" encoding="utf-8"?><TextViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/TextView"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24dp"android:padding="10px"android:shadowColor="#f0f"android:shadowDx="4"android:shadowDy="4"android:shadowRadius="2"/>
checked_item.xml代码:
<?xml version="1.0" encoding="utf-8"?><CheckedTextViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/TextView"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24dp"android:checkMark="@drawable/ok"android:shadowColor="#f0f"android:shadowDx="4"android:shadowDy="4"android:shadowRadius="2"/>
显示效果:
0 0
- ArrayAdapter创建ListView学习笔记
- Android学习笔记之ListView采用ArrayAdapter
- ArrayAdapter创建ListView
- 安卓自学笔记:6:用ArrayAdapter创建ListView
- Android开发学习笔记(十一)ListView/ActivityManager/ArrayAdapter学习
- listview学习之arrayadapter初探
- 【Android】利用ArrayAdapter/SimpleAdapter创建ListView
- 笔记20 使用ArrayAdapter、ArrayAdapter为ListView添加数据
- ListView-Arrayadapter
- ListView ArrayAdapter
- ListView+ArrayAdapter
- Android列表视图(ListView--ArrayAdapter)学习
- Android列表视图(ListView--ArrayAdapter)学习
- android客户端学习-listview及simpleadapter,arrayadapter
- Android学习笔记(10)————Android的Listview详解1(ArrayAdapter方式)
- Android学习笔记(10)————Android的Listview详解1(ArrayAdapter方式) .
- Android学习笔记之——ListView 的两种适配器ArrayAdapter和SimpleAdapter
- ArrayAdapter和自己创建BaseAdapter用于ListView的示例
- html及css学习笔记_13_css三种选择器(selector)
- C语言中从大到小的顺序排列《学习记录》
- NYOJ 289 苹果
- day03
- 155.Min Stack(求一个栈中的最小元素)
- ArrayAdapter创建ListView学习笔记
- Java里多个Map的性能比较(TreeMap、HashMap、ConcurrentSkipListMap)
- day04
- android framework 源码结构图
- 提示不能从“const char *”转换为“LPCWSTR” 的解决办法
- linux 下 动态库的编写和使用
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
- 常用正则表达式
- day05