• home > OS > Android > Develop >

    android分组列表开发

    Author:[email protected] Date:

    android分组列表开发,这个功能经常用到。别入通讯录什么的的。
    android分组列表开发

    代码打包下载
    http://zhoulujun.qiniudn.com/
    ListGroupExpandableListView.zip

    package cn.zhoulujun;
    
    import android.app.ExpandableListActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.Window;
    import android.widget.ExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.Toast;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class ListGroupExpandableListView extends ExpandableListActivity {
        private String[] group=new String[]{"同学","同事","家人"};
        private String[][] groupDetail=new String[][]{
                {"罗志彪","刘宋","刘定飞","刘丹"},
                {"潘光浩","梁建坤","张晓峰","张无忌"},
                {"周静","李世婕","李世民","李元芳"}
        };
    
        ExpandableListView expandableListView;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.list_view);
            expandableListView=(ExpandableListView)findViewById(R.id.expandListView);
            ExpandableListAdapter adapter=new ListAdpater(this,group,groupDetail);
            expandableListView.setAdapter(adapter);
            expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
                @Override
                public void onGroupExpand(int groupPosition) {
    
                }
            });
            expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
                @Override
                public void onGroupCollapse(int groupPosition) {
    
                }
            });
            expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                    Toast.makeText(ListGroupExpandableListView.this,group[groupPosition]+":"+groupDetail[groupPosition][childPosition],Toast.LENGTH_SHORT).show();
                    return false;
                }
            });
    
    
        }
    
    }
    
    
    
    package cn.zhoulujun;  import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter;  import java.util.ArrayList; import java.util.Objects;  /**  * Created by lujun on 2015-07-22.  */ public class MyExpandableAdapter extends BaseExpandableListAdapter { private Activity activity;  private String[][] childItems;  private LayoutInflater inflater;  private String[] prarentItems,child;   public MyExpandableAdapter(String[] prarentItems, String[][] childItems) { this.prarentItems = prarentItems;  this.childItems = childItems;  } public void setInflater(LayoutInflater inflater,Activity activity){ this.inflater=inflater;  this.activity=activity;  } @Override  public int getGroupCount() { return 0;  } @Override  public int getChildrenCount(int groupPosition) { return 0;  } @Override  public Object getGroup(int groupPosition) { return null;  } @Override  public Object getChild(int groupPosition, int childPosition) { return null;  } @Override  public long getGroupId(int groupPosition) { return 0;  } @Override  public long getChildId(int groupPosition, int childPosition) { return 0;  } @Override  public boolean hasStableIds() { return false;  } @Override  public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { return null;  } @Override  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { child = childItems[groupPosition];  return null;  } @Override  public boolean isChildSelectable(int groupPosition, int childPosition) { return false;  } } 
    xml version="1.0" encoding="utf-8"?>
    
    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:orientation="vertical"
                    android:id="@+id/ListGroupItem"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    android:id="@+id/listGroupImage"
                android:layout_width="30dp"
                android:layout_height="40dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:src="@drawable/arrow_up"
                android:backgroundTintMode="src_in"/>
                    android:id="@+id/listGroupName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignBaseline="@id/listGroupImage"
                android:layout_toRightOf="@+id/listGroupImage"
                android:textSize="24sp"
                android:text="分组名称"/>
                    android:id="@+id/listGroupNum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignBottom="@id/listGroupImage"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:text="[10/10]"/>
    
    
    
    
    
    
    
    xml version="1.0" encoding="utf-8"?>
    
    xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="40dp">
                    android:id="@+id/listChildAvatar"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="10dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:src="@drawable/avatar"
                />
                    android:id="@+id/listViewNick"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/listChildAvatar"
                android:layout_marginLeft="10dp"
                android:text="昵称"
                android:textSize="16sp"/>
                    android:id="@+id/listViewTrends"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/listViewNick"
                android:layout_alignParentBottom="true"
                android:text="该好友没有最新动态"
                android:textSize="12sp"/>
    
    
    


    转载本站文章《android分组列表开发》,
    请注明出处:https://www.zhoulujun.cn/html/OS/Android/AndroidDevelop/2015_0727_175.html