首页 文章 精选 留言 我的

精选列表

搜索[UI库],共10000篇文章
优秀的个人博客,低调大师

Android UI开发第五篇——自定义列表

自定义列表,设置列表背景、列表的列背景、列表的间隔线。 借鉴了一些前辈的代码。 MainActivity.class public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //绑定Layout里面的ListView ListView list = (ListView) findViewById(R.id.ListView01); //生成动态数组,加入数据 ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>(); for(int i=0;i<5;i++) { if(i==0){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.checked);//图像资源的ID map.put("ItemTitle", "个人信息"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==1){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.c);//图像资源的ID map.put("ItemTitle", "修改密码"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==2){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.d);//图像资源的ID map.put("ItemTitle", "网络设置"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else if(i==3){ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.d);//图像资源的ID map.put("ItemTitle", "打印设置"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); }else{ HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.e);//图像资源的ID map.put("ItemTitle", "返回"); map.put("LastImage", R.drawable.lastimage); listItem.add(map); } } //生成适配器的Item和动态数组对应的元素 SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,// 数据源 R.layout.list_items,//ListItem的XML实现 //动态数组与ImageItem对应的子项 new String[] {"ItemImage","ItemTitle", "LastImage"}, //ImageItem的XML文件里面的一个ImageView,两个TextView ID new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.last} ); //添加并且显示 list.setAdapter(listItemAdapter); //添加点击 list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { setTitle("点击第"+arg2+"个项目"); if(arg2 == 4){ MainActivity.this.finish(); } } }); //添加长按点击 list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) { menu.setHeaderTitle("长按菜单-ContextMenu"); menu.add(0, 0, 0, "弹出长按菜单0"); menu.add(0, 1, 0, "弹出长按菜单1"); } }); } //长按菜单响应函数 @Override public boolean onContextItemSelected(MenuItem item) { setTitle("点击了长按菜单里面的第"+item.getItemId()+"个项目"); return super.onContextItemSelected(item); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" xmlns:android="http://schemas.android.com/apk/res/android"> <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ListView01" android:divider="@drawable/divider_color" android:dividerHeight="3dip" android:cacheColorHint="#00000000" /> </LinearLayout> list_item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingBottom="4dip" android:paddingLeft="12dip" android:paddingRight="12dip" android:background="@drawable/list_bg"> <ImageView android:paddingTop="12dip" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ItemImage" /> <TextView android:text="TextView01" android:layout_height="wrap_content" android:layout_marginTop="30px" android:textSize="20dip" android:paddingLeft="12dip" android:textColor="#000000" android:layout_width="fill_parent" android:id="@+id/ItemTitle" android:layout_toRightOf="@+id/ItemImage" /> <ImageView android:paddingTop="12dip" android:layout_marginTop="20px" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/last" /> </RelativeLayout> http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 http://www.devdiv.com/forum.php?mod=viewthread&tid=97913&page=1#pid591587 http://blog.csdn.net/zeng622peng/archive/2010/08/11/5804965.aspx http://www.devdiv.com/home.php?mod=space&uid=14682&do=blog&id=2888 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817375 ,如需转载请自行联系原作者

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册