备忘——仿QQ分组ExpandableListView(差强人意)修改过

网上查了下,然后知道就是在ExpandableListView上加个LinearLayout当指示器(不管是什么,一样效果就行,像QQ是自定义控件,很强大,可惜他不放源码出来),,,

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" >

    <ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:groupIndicator="@null"
        android:background="@color/whilte" >
    </ExpandableListView>

    <LinearLayout
        android:id="@+id/listView_guide"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@color/whilte"
        android:orientation="vertical" >

    </LinearLayout>

</RelativeLayout>

 Activity:

OnClickListener myoClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			expandableListView_relationship.collapseGroup(gruopNum);
			listGuide.setVisibility(View.GONE);
		}
	};

	OnScrollListener myoOnScrollListener = new OnScrollListener() {
		
		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			// TODO Auto-generated method stub

		}

@Override
		public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
			// TODO Auto-generated method stub
			TextView textNum = (TextView) view.findViewById(R.id.textView_num);//组标记			
			if (textNum != null) {
				gruopNum = Integer.valueOf(textNum.getText().toString());// 在adapter手动存
				if (expandableListView_relationship.isGroupExpanded(gruopNum)) {
					TextView childNum = (TextView) view.findViewById(R.id.child_num);//child标记
					// 已经打开
					int childCount = adapter.getChildrenCount(gruopNum) - 1;
					if(childCount<0){
      //没有child的,返回
      listGuide.setVisibility(View.GONE);  
      return;
     }
					if (childNum != null) {
						int childnum = Integer.valueOf(childNum.getText().toString());// 在adapter手动存				
						if (childCount == childnum) {
							// 最后一个child
							listGuide.setVisibility(View.GONE);		
							return;
						}
					}					
					listGuide.setVisibility(View.VISIBLE);
					gruopView = adapter.getGroupView(gruopNum, true, gruopView, null);//重新进来时,gruopView=null, 不然会报removeView()的错
					if(isFist){
						listGuide.addView(gruopView);
						isFist = false;
					}
					listGuide.invalidate();
				} else {
					listGuide.setVisibility(View.GONE);
				}				
			}
		}
	};

相关推荐