SHOW:
|
|
- or go back to the newest paste.
| 1 | - | package com.dooble.pushit; |
| 1 | + | |
| 2 | ||
| 3 | import android.content.Context; | |
| 4 | import android.view.LayoutInflater; | |
| 5 | import android.view.View; | |
| 6 | import android.view.ViewGroup; | |
| 7 | import android.widget.AbsListView; | |
| 8 | import android.widget.BaseExpandableListAdapter; | |
| 9 | import android.widget.ExpandableListView; | |
| 10 | import android.widget.TextView; | |
| 11 | ||
| 12 | public class CatAdapter extends BaseExpandableListAdapter {
| |
| 13 | private Context context; | |
| 14 | private LayoutInflater inflater; | |
| 15 | private ArrayList<Category> categories; | |
| 16 | ||
| 17 | public CatAdapter(Context context, ArrayList<Category> categories) {
| |
| 18 | this.context = context; | |
| 19 | inflater = LayoutInflater.from(context); | |
| 20 | this.categories = categories; | |
| 21 | } | |
| 22 | ||
| 23 | @Override | |
| 24 | public Object getChild(int groupPosition, int childPosition) {
| |
| 25 | return categories.get(groupPosition).childs.get(childPosition); | |
| 26 | } | |
| 27 | ||
| 28 | @Override | |
| 29 | public long getChildId(int groupPosition, int childPosition) {
| |
| 30 | return childPosition; | |
| 31 | } | |
| 32 | ||
| 33 | @Override | |
| 34 | public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
| |
| 35 | ||
| 36 | convertView = inflater.inflate(R.layout.catitem, parent, false); | |
| 37 | TextView textView_catName = (TextView)convertView.findViewById(R.id.textView_catName); | |
| 38 | Category current = categories.get(groupPosition).childs.get(childPosition); | |
| 39 | textView_catName.setText(groupPosition + " , " + childPosition); | |
| 40 | ||
| 41 | if(current.childs.size() > 0 ) {
| |
| 42 | ExpandableListView elv = new ExpandableListView(context); | |
| 43 | elv.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT, AbsListView.LayoutParams.WRAP_CONTENT)); | |
| 44 | elv.setAdapter(new CatAdapter(context, current.childs)); | |
| 45 | ((ViewGroup)convertView).addView(elv); | |
| 46 | } | |
| 47 | ||
| 48 | return convertView; | |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | public int getChildrenCount(int groupPosition) {
| |
| 53 | return categories.get(groupPosition).childs.size(); | |
| 54 | } | |
| 55 | ||
| 56 | @Override | |
| 57 | public Object getGroup(int groupPosition) {
| |
| 58 | return categories.get(groupPosition); | |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public int getGroupCount() {
| |
| 63 | return categories.size(); | |
| 64 | } | |
| 65 | ||
| 66 | @Override | |
| 67 | public long getGroupId(int groupPosition) {
| |
| 68 | return groupPosition; | |
| 69 | } | |
| 70 | ||
| 71 | @Override | |
| 72 | public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
| |
| 73 | convertView = inflater.inflate(R.layout.catitem, parent, false); | |
| 74 | TextView textView_catName = (TextView)convertView.findViewById(R.id.textView_catName); | |
| 75 | Category current = categories.get(groupPosition); | |
| 76 | textView_catName.setText("" + groupPosition);
| |
| 77 | ||
| 78 | return convertView; | |
| 79 | } | |
| 80 | ||
| 81 | @Override | |
| 82 | public boolean hasStableIds() {
| |
| 83 | return false; | |
| 84 | } | |
| 85 | ||
| 86 | @Override | |
| 87 | public boolean isChildSelectable(int groupPosition, int childPosition) {
| |
| 88 | return false; | |
| 89 | } | |
| 90 | } |