android 中可展开控件ExpandableListView的使用
来源:互联网 发布:人工智能学术会议 编辑:程序博客网 时间:2024/05/16 05:30
布局文件三个:
1.expandalistview_layout.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/main_bg" android:orientation="vertical" > <ExpandableListView android:id="@+id/expandablelist" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_below="@id/common_problem_bar" android:layout_marginBottom="50dip" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:layout_marginTop="10dip" android:background="@color/white" android:drawSelectorOnTop="false" > </ExpandableListView></RelativeLayout>
2.一级视图布局
common_problem_group_item.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation = "horizontal"android:layout_width="match_parent"android:layout_height="40dip"android:background="@color/white"><!-- 常见问题的ExpandableListView group 布局 --><TextViewandroid:id = "@+id/textView01"android:layout_width ="match_parent"android:layout_height = "match_parent"android:layout_marginTop="10dip"android:layout_marginBottom="10dip"android:layout_marginLeft="40dip"android:layout_marginRight="10dip"android:textSize = "18dip"/></RelativeLayout>
3.二级视图 common_problem_child_item
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <!-- 常见问题的ExpandableListView child 布局 --> <TextView android:id="@+id/childTo" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:paddingBottom="5px" android:paddingLeft="30px" android:paddingTop="10px" android:textColor="@color/gray" android:textSize="15dip" /></LinearLayout><span style="color:#0326cc;"></span>
</pre><pre name="code" class="html">准备数据
// 一级数据
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Monaco;"><pre name="code" class="java">private static final int[] problemSubIds = new int[] { R.string.problem_sub0, R.string.problem_sub1, R.string.problem_sub2,R.string.problem_sub3, R.string.problem_sub4 };<pre name="code" class="html" style="font-size: 18px;">// 二级数据
private static final int[][] problemContentIds = new int[][] { { R.string.problem_content0 }, { R.string.problem_content1 },{ R.string.problem_content2 }, { R.string.problem_content3 }, { R.string.problem_content4 } };
绑定适配器
mExpandableListView = (ExpandableListView) v.findViewById(R.id.expandablelist);
mExpandableListView.setAdapter(new ExpandableAdapter(getActivity(), problemSubIds, problemContentIds));
ExpandableAdapter适配器
package com.toughegg.teclient.adapter;import android.annotation.SuppressLint;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.TextView;import com.toughegg.teclient.R;@SuppressLint("InflateParams")public class ExpandableAdapter extends BaseExpandableListAdapter {private Context context;private int[] problemypes;private int[][] problemdetail;public ExpandableAdapter(Context context, int[] problemypes, int[][] problemdetail) {this.context = context;this.problemypes = problemypes;this.problemdetail = problemdetail;}@Overridepublic Object getChild(int groupPosition, int childPosition) {return problemdetail[groupPosition][childPosition];}@Overridepublic long getChildId(int groupPosition, int childPosition) {return childPosition;}@Overridepublic View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {int text = problemdetail[groupPosition][childPosition];LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);LinearLayout linearLayout = (LinearLayout) layoutInflater.inflate(R.layout.te_common_problem_child, null);TextView tv = (TextView) linearLayout.findViewById(R.id.childTo);tv.setText(text);return linearLayout;}@Overridepublic int getChildrenCount(int groupPosition) {return problemdetail[groupPosition].length;}@Overridepublic Object getGroup(int groupPosition) {return problemypes[groupPosition];}@Overridepublic int getGroupCount() {return problemypes.length;}@Overridepublic long getGroupId(int groupPosition) {return groupPosition;}// 获取一级列表View对象@Overridepublic View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {int text = problemypes[groupPosition];LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);RelativeLayout linearLayout = (RelativeLayout) layoutInflater.inflate(R.layout.te_common_problem_group_xml, null);TextView textView = (TextView) linearLayout.findViewById(R.id.textView01);textView.setText(text);return linearLayout;}@Overridepublic boolean hasStableIds() {return true;}@Overridepublic boolean isChildSelectable(int groupPosition, int childPosition) {return true;}}
0 0
- android 中可展开控件ExpandableListView的使用
- Android中可展开的列表组件(ExpandableListView)的使用
- ExpandableListview控件使用---可展开的列表组件
- ExpandableListView的使用,可展开的ListView
- Android ExpandableListView 可展开的ListView
- 关于android中ExpandableListView控件的展开刷新问题
- Android中ExpandableListView控件的使用
- Android 使用ExpandableListView打造可展开列表组件
- Android ExpandableListView 展开列表控件
- Android开发之ExpandableListView: 可展开的ListView
- Android可展开的列表组件(ExpandableListView)模板
- Android 可展开列表组件 ExpandableListView
- Android高级控件之ExpandableListView可以展开的listview
- 可展开的列表组件ExpandableListView
- 可展开的列表组件ExpandableListView
- 可展开的列表组件ExpandableListView
- ExpandableListView-可展开的列表组件
- 可展开的列表组件 ExpandableListview
- POJ1328 -- 贪心算法和快速排序
- [C/C++ 开发] 中如何获取数组的长度
- vs2008下搭建GTK+开发环境的搭建指南
- MySQL utf8mb4 字符集
- 公开付费的非关系数据库:百度对象存储BOS
- android 中可展开控件ExpandableListView的使用
- Spring管理Struts Action
- overridePendingTransition的简介 (activity之间跳转的动画设置)
- 使用jasperreposts生成报表方法二,三
- Xcode svn import项目 上传.a文件(静态库)
- Mysql用户权限管理
- fragment中使用sharedPreferences保存数据。
- java servlet 几种页面跳转的方法
- request.getContextPath(),request.getServletPath() 区别