- 浏览: 66497 次
- 性别:
- 来自: 北京
最新评论
-
创世雨天:
转换后getText就会是乱码 请问有解决办法吗?QQ4027 ...
EditText加入图片混编显示 -
logojimi:
楼主考虑了安装多种桌面,而且没有设置默认桌面的情况?
试试这行 ...
Android程序最小化 -
yuboxin5566:
这个东西可以具体点吗?我可以有你这个东东的全代码么?可以私聊Q ...
EditText加入图片混编显示 -
woaidousha:
那请问个问题,如果是想在listView下面加个expanda ...
ExpandableListView 怎么和其他组件相互整合布局 -
liutao6982:
厉害厉害。这一招都被你想出来啦。很好很强大。支持一下
EditText加入图片混编显示
这个例子可以学习到如下几点:
1.通过自定义Dialog(单独布局的xml文件进行弹出显示)
2.通过menu点击监听添加,删除view中的items
3.点击ExpandableListView中group和child的事件监听
下面是代码:
1.ExpandableListViewStudy.java
- package cn.com.example;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.app.Dialog;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ExpandableListView;
- import android.widget.Toast;
- import android.widget.ExpandableListView.OnChildClickListener;
- import android.widget.ExpandableListView.OnGroupClickListener;
- public class ExpandableListViewStudy extends Activity {
- public final static int MENU_ADD = Menu.FIRST;
- public final static int MENU_DELETE = Menu.FIRST + 1;
- ExpandableListView expandList;
- InfoDetailsAdapter adapter;
- Activity activity;
- List<String> group;
- List<List<String>> child;
- // 初始化group child内容
- public void initialData() {
- group = new ArrayList<String>();
- child = new ArrayList<List<String>>();
- addInfo("group 1", new String[] { "one 1", "two 1", "three 1" });
- addInfo("group 2", new String[] { "one 2", "two 2", "three 2" });
- addInfo("group 3", new String[] { "one 3", "two 3", "three 3" });
- }
- public void addInfo(String p, String[] c) {
- group.add(p);
- List<String> item = new ArrayList<String>();
- for (int i = 0; i < c.length; i++) {
- item.add(c[i]);
- }
- child.add(item);
- }
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- activity = this;
- expandList = (ExpandableListView) findViewById(R.id.expandList);
- // 初始化各级元素
- initialData();
- // 适配器内容
- adapter = new InfoDetailsAdapter(this, group, child);
- expandList.setAdapter(adapter);
- expandList.setOnGroupClickListener(new OnGroupClickListener() {
- @Override
- public boolean onGroupClick(ExpandableListView arg0, View arg1,
- int arg2, long arg3) {
- // TODO Auto-generated method stub
- System.out.println("The row id of the group clicked" + arg3);
- Toast.makeText(activity, "[Group Click]:" + arg2,
- Toast.LENGTH_SHORT).show();
- return false;
- }
- });
- expandList.setOnChildClickListener(new OnChildClickListener() {
- @Override
- public boolean onChildClick(ExpandableListView arg0, View arg1,
- int arg2, int arg3, long arg4) {
- // TODO Auto-generated method stub
- Toast.makeText(activity, "[Child Click]:" + arg2 + ":" + arg3,
- Toast.LENGTH_SHORT).show();
- return false;
- }
- });
- }
- // 下述2个函数处理Menu按钮的事件
- public boolean onCreateOptionsMenu(Menu menu) {
- // TODO Auto-generated method stub
- menu.add(0, MENU_ADD, 0, " 添加 ");
- menu.add(0, MENU_DELETE, 0, " 删除 ");
- return super.onCreateOptionsMenu(menu);
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case MENU_ADD:
- Log.i("", "FRIEND_ID");
- createDialogAdd();
- dialogAdd.show();
- break;
- case MENU_DELETE:
- Log.i("", "FRIEND_ID");
- createDialogDelete();
- dialogDelete.show();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- EditText add_name, add_phone, add_sex, add_home;
- EditText delete_id;
- Button add_ok, add_no;
- Button delete_ok, delete_no;
- Dialog dialogAdd, dialogDelete;
- public void createDialogAdd() {
- Log.i("", "createDialogAdd");
- View viewAdd = this.getLayoutInflater().inflate(R.layout.add, null);
- dialogAdd = new Dialog(this);
- dialogAdd.setContentView(viewAdd);
- dialogAdd.setTitle("输入新成员信息");
- add_name = (EditText) viewAdd.findViewById(R.id.add_name);
- add_phone = (EditText) viewAdd.findViewById(R.id.add_phone);
- add_sex = (EditText) viewAdd.findViewById(R.id.add_sex);
- add_home = (EditText) viewAdd.findViewById(R.id.add_home);
- add_ok = (Button) viewAdd.findViewById(R.id.add_ok);
- add_no = (Button) viewAdd.findViewById(R.id.add_no);
- add_ok.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String[] data = { add_phone.getText().toString(),
- add_sex.getText().toString(),
- add_home.getText().toString() };
- addInfo(add_name.getText().toString(), data);
- dialogAdd.dismiss();
- adapter.notifyDataSetChanged();
- }
- });
- add_no.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- dialogAdd.dismiss();
- }
- });
- }
- public void createDialogDelete() {
- View viewDelete = this.getLayoutInflater().inflate(R.layout.delete,
- null);
- dialogDelete = new Dialog(this);
- dialogDelete.setContentView(viewDelete);
- dialogDelete.setTitle("删除指定成员");
- delete_id = (EditText) viewDelete.findViewById(R.id.delete_id);
- delete_ok = (Button) viewDelete.findViewById(R.id.delete_ok);
- delete_no = (Button) viewDelete.findViewById(R.id.delete_no);
- delete_ok.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String id = delete_id.getText().toString();
- if (!id.equals("")) {
- int i = Integer.parseInt(id);
- group.remove(i);
- child.remove(i);
- dialogDelete.dismiss();
- adapter.notifyDataSetChanged();
- }
- }
- });
- delete_no.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- dialogDelete.dismiss();
- }
- });
- }
- }
package cn.com.example; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.Toast; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ExpandableListView.OnGroupClickListener; public class ExpandableListViewStudy extends Activity { public final static int MENU_ADD = Menu.FIRST; public final static int MENU_DELETE = Menu.FIRST + 1; ExpandableListView expandList; InfoDetailsAdapter adapter; Activity activity; List<String> group; List<List<String>> child; // 初始化group child内容 public void initialData() { group = new ArrayList<String>(); child = new ArrayList<List<String>>(); addInfo("group 1", new String[] { "one 1", "two 1", "three 1" }); addInfo("group 2", new String[] { "one 2", "two 2", "three 2" }); addInfo("group 3", new String[] { "one 3", "two 3", "three 3" }); } public void addInfo(String p, String[] c) { group.add(p); List<String> item = new ArrayList<String>(); for (int i = 0; i < c.length; i++) { item.add(c[i]); } child.add(item); } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); activity = this; expandList = (ExpandableListView) findViewById(R.id.expandList); // 初始化各级元素 initialData(); // 适配器内容 adapter = new InfoDetailsAdapter(this, group, child); expandList.setAdapter(adapter); expandList.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub System.out.println("The row id of the group clicked" + arg3); Toast.makeText(activity, "[Group Click]:" + arg2, Toast.LENGTH_SHORT).show(); return false; } }); expandList.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3, long arg4) { // TODO Auto-generated method stub Toast.makeText(activity, "[Child Click]:" + arg2 + ":" + arg3, Toast.LENGTH_SHORT).show(); return false; } }); } // 下述2个函数处理Menu按钮的事件 public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0, MENU_ADD, 0, " 添加 "); menu.add(0, MENU_DELETE, 0, " 删除 "); return super.onCreateOptionsMenu(menu); } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_ADD: Log.i("", "FRIEND_ID"); createDialogAdd(); dialogAdd.show(); break; case MENU_DELETE: Log.i("", "FRIEND_ID"); createDialogDelete(); dialogDelete.show(); break; } return super.onOptionsItemSelected(item); } EditText add_name, add_phone, add_sex, add_home; EditText delete_id; Button add_ok, add_no; Button delete_ok, delete_no; Dialog dialogAdd, dialogDelete; public void createDialogAdd() { Log.i("", "createDialogAdd"); View viewAdd = this.getLayoutInflater().inflate(R.layout.add, null); dialogAdd = new Dialog(this); dialogAdd.setContentView(viewAdd); dialogAdd.setTitle("输入新成员信息"); add_name = (EditText) viewAdd.findViewById(R.id.add_name); add_phone = (EditText) viewAdd.findViewById(R.id.add_phone); add_sex = (EditText) viewAdd.findViewById(R.id.add_sex); add_home = (EditText) viewAdd.findViewById(R.id.add_home); add_ok = (Button) viewAdd.findViewById(R.id.add_ok); add_no = (Button) viewAdd.findViewById(R.id.add_no); add_ok.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String[] data = { add_phone.getText().toString(), add_sex.getText().toString(), add_home.getText().toString() }; addInfo(add_name.getText().toString(), data); dialogAdd.dismiss(); adapter.notifyDataSetChanged(); } }); add_no.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub dialogAdd.dismiss(); } }); } public void createDialogDelete() { View viewDelete = this.getLayoutInflater().inflate(R.layout.delete, null); dialogDelete = new Dialog(this); dialogDelete.setContentView(viewDelete); dialogDelete.setTitle("删除指定成员"); delete_id = (EditText) viewDelete.findViewById(R.id.delete_id); delete_ok = (Button) viewDelete.findViewById(R.id.delete_ok); delete_no = (Button) viewDelete.findViewById(R.id.delete_no); delete_ok.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub String id = delete_id.getText().toString(); if (!id.equals("")) { int i = Integer.parseInt(id); group.remove(i); child.remove(i); dialogDelete.dismiss(); adapter.notifyDataSetChanged(); } } }); delete_no.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub dialogDelete.dismiss(); } }); } }
2.InfoDetailsAdapter.java(适配器文件,用于提供给View内容)
- package cn.com.example;
- import java.util.List;
- import android.app.Activity;
- import android.view.Gravity;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AbsListView;
- import android.widget.BaseExpandableListAdapter;
- import android.widget.TextView;
- //为expandable list view 提供内容的基类
- public class InfoDetailsAdapter extends BaseExpandableListAdapter {
- Activity activity;
- List<String> group;
- List<List<String>> child;
- public InfoDetailsAdapter(Activity a, List<String> group,
- List<List<String>> child) {
- activity = a;
- this.group = group;
- this.child = child;
- }
- // child method stub
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- // TODO Auto-generated method stub
- // System.out.println("*******************"+child.get(groupPosition).get(childPosition));
- return child.get(groupPosition).get(childPosition);
- }
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- // TODO Auto-generated method stub
- return childPosition;
- }
- @Override
- public int getChildrenCount(int groupPosition) {
- // TODO Auto-generated method stub
- return child.get(groupPosition).size();
- }
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- String string = child.get(groupPosition).get(childPosition);
- return getGenericView(string);
- }
- // group method stub
- @Override
- public Object getGroup(int groupPosition) {
- // TODO Auto-generated method stub
- return group.get(groupPosition);
- }
- @Override
- public long getGroupId(int groupPosition) {
- // TODO Auto-generated method stub
- return groupPosition;
- }
- @Override
- public int getGroupCount() {
- // TODO Auto-generated method stub
- return group.size();
- }
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- String string = group.get(groupPosition);
- return getGenericView(string);
- }
- // View stub to create Group/Children 's View
- public TextView getGenericView(String s) {
- // Layout parameters for the ExpandableListView
- AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT, 64);
- TextView text = new TextView(activity);
- text.setLayoutParams(lp);
- // Center the text vertically
- text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
- // Set the text starting position
- text.setPadding(36, 0, 0, 0);
- text.setText(s);
- return text;
- }
- @Override
- public boolean hasStableIds() {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- // TODO Auto-generated method stub
- return true;
- }
- }
package cn.com.example; import java.util.List; import android.app.Activity; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; //为expandable list view 提供内容的基类 public class InfoDetailsAdapter extends BaseExpandableListAdapter { Activity activity; List<String> group; List<List<String>> child; public InfoDetailsAdapter(Activity a, List<String> group, List<List<String>> child) { activity = a; this.group = group; this.child = child; } // child method stub @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub // System.out.println("*******************"+child.get(groupPosition).get(childPosition)); return child.get(groupPosition).get(childPosition); } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return child.get(groupPosition).size(); } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { // TODO Auto-generated method stub String string = child.get(groupPosition).get(childPosition); return getGenericView(string); } // group method stub @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return group.get(groupPosition); } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public int getGroupCount() { // TODO Auto-generated method stub return group.size(); } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { // TODO Auto-generated method stub String string = group.get(groupPosition); return getGenericView(string); } // View stub to create Group/Children 's View public TextView getGenericView(String s) { // Layout parameters for the ExpandableListView AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 64); TextView text = new TextView(activity); text.setLayoutParams(lp); // Center the text vertically text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); // Set the text starting position text.setPadding(36, 0, 0, 0); text.setText(s); return text; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } }
至于里面的方法各自起什么作用,可以自己进行测试
3.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" android:id="@+id/layout">
- <ExpandableListView android:id="@+id/expandList"
- android:layout_width="fill_parent" android:layout_height="wrap_content" />
- </LinearLayout>
<?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" android:id="@+id/layout"> <ExpandableListView android:id="@+id/expandList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
4.add.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">
- <LinearLayout android:orientation="horizontal"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="姓名:" />
- <EditText android:id="@+id/add_name" android:layout_width="200dip"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout android:orientation="horizontal"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="电话:" />
- <EditText android:id="@+id/add_phone" android:layout_width="200dip"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout android:orientation="horizontal"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="性别:" />
- <EditText android:id="@+id/add_sex" android:layout_width="200dip"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout android:orientation="horizontal"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="住址:" />
- <EditText android:id="@+id/add_home" android:layout_width="200dip"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout android:orientation="horizontal"
- android:layout_width="wrap_content" android:layout_height="wrap_content">
- <Button android:id="@+id/add_ok" android:layout_width="90dip"
- android:layout_height="wrap_content" android:text="OK" />
- <Button android:id="@+id/add_no" android:layout_width="90dip"
- android:layout_height="wrap_content" android:text="NO" />
- </LinearLayout>
- </LinearLayout>
<?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"> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名:" /> <EditText android:id="@+id/add_name" android:layout_width="200dip" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="电话:" /> <EditText android:id="@+id/add_phone" android:layout_width="200dip" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别:" /> <EditText android:id="@+id/add_sex" android:layout_width="200dip" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="住址:" /> <EditText android:id="@+id/add_home" android:layout_width="200dip" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:orient发表评论
-
Android程序最小化
2011-03-25 14:30 2281/** * 最小化,回到桌面 * */ ... -
Android开发中如何定义和使用数组
2011-03-02 17:12 1670数组在Android开发中是如何定义和使用的呢? 在Andro ... -
EditText加入图片混编显示
2011-02-23 10:32 4060Android的WebView固然强大 ... -
Eclipse中Logcat中文解决办法,重装该ADT即可
2011-02-16 16:57 2574这个问题从一开始接触到Android开发就困扰我很久 ... -
Android 核心分析 之五 -----基本空间划分【转】
2011-01-18 14:23 805基本空间划分 Google给了我们一张系统架构图,在这张图上 ... -
Android核心分析之四 ---手机的软件形态【转】
2011-01-18 14:17 770手机的软件形态 上节我给出了手机的硬件树,本节将 ... -
Android是什么 之三-------手机之硬件形态【转】
2011-01-18 14:16 906Android是什么 之三-------手机之硬件形态 ... -
Android核心分析 之一--------分析方法论探讨之设计意图【转】
2011-01-18 14:09 815分析方法论探讨之设计 ... -
获取string.xml中的可变字符串
2011-01-14 15:47 20181、在string.xml中添加一个字符串,其中含有可变字符% ... -
在代码中获取在AndroidManifest.xml中配置的版本号
2011-01-14 15:42 1744在代码中的获取方法如下: String versionnam ... -
android2.1源码开发过程中的小技巧
2010-12-29 15:07 960归纳总结android2.1源码开发过程中的一些实用的小技巧。 ... -
升级Android SDK到2.3错误的解决办法
2010-12-29 15:01 975升级了2.3的朋友应该知道,升级到2.3后,Eclipse会报 ... -
Android如何解析Intent Filter (转)
2010-12-29 11:22 707匿名性质的运行时绑定使得理解Android如何解析一个隐式 ... -
使用JSON-LIB转换JAVA对象
2010-12-29 11:20 1031使用JSON-LIB可以极大的简化JAVA对象转换成 ... -
Android应用程序中Manifest.java文件的介绍(转)
2010-12-29 11:13 1706每一个Android应用程序包含一个manifest文件——A ... -
Android使用外部字体
2010-12-23 11:31 1441有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引 ... -
动态获取drawable中的图片
2010-12-22 15:45 13041.首先在drawable中创建一定格式命名的图片。 2.在 ... -
Android配置文件(.properties文件)的使用
2010-12-20 16:39 50041.首先在源代码根目录(src下)下创建一个名为netconf ... -
Android 中离线用户的灰色头像处理方法
2010-12-20 14:04 1107android的图片资源默认是静态的,也就是说是单实例的;如果 ... -
Android Intent Action 大全
2010-12-17 18:59 662String ADD_SHORTCUT_ACTION 动作 ...
相关推荐
4. **界面布局**:在XML布局文件中添加`ExpandableListView`,并为其设置适配器。 下面是一些关键步骤的详细说明: **步骤1:数据模型** ```java public class Group { private String groupName; private List...
本篇文章将详细探讨如何在Android中使用ExpandableListView进行动态添加和删除操作,以及实现ListView的选择和删除功能。 首先,我们来看ExpandableListView。它是一种特殊的ListView,允许每个条目展开显示子条目...
当涉及到用户体验优化时,改变`ExpandableListView`子item选中状态的颜色是一种常见做法,可以提高用户的交互感知。在本篇文章中,我们将深入探讨如何实现这一功能。 首先,我们需要理解`ExpandableListView`的基本...
在这个例子中,我们将会深入探讨如何利用`ExpandableListView`来创建一个可展开和折叠的菜单系统,实现丰富的交互效果。 `ExpandableListView`与普通的`ListView`相比,其主要优势在于它支持子项的展开和收缩,这...
在Android开发中,有时我们需要创建复杂布局以满足用户界面的需求,比如在`ExpandableListView`中嵌套时间轴。`ExpandableListView`是Android提供的一个可扩展的列表视图,它可以展示分组数据,每组数据可以展开或...
总之,这个例子是关于如何在Android应用中使用ExpandableListView实现一个多级菜单分类展示的实战教程。通过研究源码和理解数据结构与事件处理,开发者能够掌握这个控件的核心用法,并将其应用于自己的项目中。
一个ExpandableListView的例子,实现多级菜单分类展示.zip安卓程序源码资源下载一个ExpandableListView的例子,实现多级菜单分类展示.zip安卓程序源码资源下载 1.适合学生做毕业设计用 2.适合程序员学习研究用 3....
一个ExpandableListView的例子,实现多级菜单分类展示.zip项目安卓应用源码下载一个ExpandableListView的例子,实现多级菜单分类展示.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3...
在Android开发中,`ExpandableListView` 是一个非常实用的控件,用于展示可以展开和折叠的列表。这个控件允许用户对数据进行分组,增强了用户体验,特别是处理层次结构数据时。本篇文章将深入探讨如何处理`...
在布局文件中,添加ExpandableListView组件,并通过FindViewById将其绑定到代码中的对象。然后,使用SetAdapter方法将之前创建的适配器设置到ExpandableListView上。这样,列表就会根据适配器提供的数据进行填充。 ...
4. **初始化并设置`ExpandableListView`**:在Activity或Fragment的布局中添加`ExpandableListView`,然后在代码中获取到它的实例。调用`setAdapter()`方法,传入之前创建的适配器。如果需要,还可以通过`...
在XML布局文件中,我们需要添加一个`ExpandableListView`控件,并设置相应的属性,如id、适配器、分隔线等。 7. **初始化与数据加载** 在Activity或Fragment的onCreate方法中,实例化适配器并设置到...
总之,通过分析`Android高级应用源码-一个ExpandableListView的例子,实现多级菜单分类展示.zip`中的源码,开发者可以学习到如何在Android应用程序中创建具有层次结构的交互式列表,这对于构建如导航菜单、目录树等...
2. 数据更新:如果需要动态添加或删除数据,可以通过适配器的方法实现,如addGroup(), removeGroup(), addChild(), removeChild()等。然后调用notifyDataSetChanged()通知列表视图数据已更改。 六、展开和折叠功能 ...
你也可能已经看到ExpandableListView一个标准的实现。然而,最近我的项目需要在屏幕方面使用这两种类型的列表。新的屏幕是有一个可折叠列表(1组ExpandableListview)的和它下面的一个标准的ListView。复杂的问题,...
在实际应用中,我们经常需要动态地生成数据并加载到ExpandableListView中,尤其是在数据量较大的情况下。然而,网上的教程大多都是针对静态数据的处理,这不适用于数据需要实时更新或动态获取的场景。本文将详细介绍...
5. **布局文件**:在布局XML文件中,添加一个ExpandableListView元素,并设置必要的属性,如`android:groupIndicator`来定制展开/折叠指示器的样式。 压缩包中的图片可能是示例应用运行截图,帮助理解显示效果。`...
5. **事件监听**:为了响应用户的点击事件,你可以为ExpandableListView添加`OnGroupClickListener`和`OnChildClickListener`。这样,当用户点击父项或子项时,可以执行相应的操作。 6. **图片资源**:压缩包中的`....