android ExpandableListView简单应用
首先我们还是来看一些案例,还是拿搜狐新闻客户端,因为我天天上下班没事爱看这个东东,因为上班没时间看新闻,上下班路途之余浏览下新闻打发时间嘛.
看这个效果挺棒吧,其实实现起来也不难,我简单说明下.
首先我们用到的控件是:ExpandableListView
布局文件:
[java]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!--
android:groupIndicator="@null" 取消默认图片
android:childIndicatorLeft 设置孩子左边间距
android:dividerHeight 这个高度一定要设置,不然显示不出来分割线,估计默认为0 吧
android:childDivider="@drawable/child_bg" 这个直接引color,或者图片会导致整个孩子背景都为这个颜色 ,不知道原因,如果有谁知道,请Give me say.
-->
<ExpandableListView
android:id="@+id/expandablelist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:childDivider="@drawable/child_bg"
android:childIndicatorLeft="0dp"
android:divider="@color/Grey"
android:dividerHeight="1dp"
android:groupIndicator="@null"
android:scrollbarAlwaysDrawHorizontalTrack="true" >
</ExpandableListView>
</RelativeLayout>
MyexpandableListAdapter.java
[java]
/***
* 数据源
*
* @author Administrator
*
*/
class MyexpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private LayoutInflater inflater;
public MyexpandableListAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}
// 返回父列表个数
@Override
public int getGroupCount() {
return groupList.size();
}
// 返回子列表个数
@Override
public int getChildrenCount(int groupPosition) {
return childList.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return groupList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return childList.get(groupPosition).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
GroupHolder groupHolder = null;
if (convertView == null) {
groupHolder = new GroupHolder();
convertView = inflater.inflate(R.layout.group, null);
groupHolder.textView = (TextView) convertView
.findViewById(R.id.group);
groupHolder.imageView = (ImageView) convertView
.findViewById(R.id.
补充:移动开发 , Android ,