1 package com
.owncloud
.android
.ui
.adapter
;
3 import android
.app
.Activity
;
4 import android
.util
.SparseArray
;
5 import android
.view
.LayoutInflater
;
6 import android
.view
.View
;
7 import android
.view
.View
.OnClickListener
;
8 import android
.view
.ViewGroup
;
9 import android
.widget
.BaseExpandableListAdapter
;
10 import android
.widget
.TextView
;
11 import android
.widget
.Toast
;
13 import com
.owncloud
.android
.R
;
15 public class MyExpandableListAdapter
extends BaseExpandableListAdapter
{
17 private final SparseArray
<Group
> groups
;
18 public LayoutInflater inflater
;
19 public Activity activity
;
21 public MyExpandableListAdapter(Activity act
, SparseArray
<Group
> groups
) {
24 inflater
= act
.getLayoutInflater();
30 public Object
getChild(int groupPosition
, int childPosition
) {
31 return groups
.get(groupPosition
).children
.get(childPosition
);
35 public long getChildId(int groupPosition
, int childPosition
) {
40 public View
getChildView(int groupPosition
, final int childPosition
,
41 boolean isLastChild
, View convertView
, ViewGroup parent
) {
42 final String children
= (String
) getChild(groupPosition
, childPosition
);
44 if (convertView
== null
) {
45 convertView
= inflater
.inflate(R
.layout
.listrow_details
, null
);
49 text
= (TextView
) convertView
.findViewById(R
.id
.textView1
);
50 text
.setText(children
);
51 convertView
.setOnClickListener(new OnClickListener() {
53 public void onClick(View v
) {
54 Toast
.makeText(activity
, children
, Toast
.LENGTH_SHORT
).show();
61 public View
getGroupView(int groupPosition
, boolean isExpanded
,
62 View convertView
, ViewGroup parent
) {
63 if (convertView
== null
) {
64 convertView
= inflater
.inflate(R
.layout
.listrow_group
, null
);
67 final Group group
= (Group
) getGroup(groupPosition
);
68 if (group
.children
.size() == 0){
69 convertView
.setOnClickListener(new OnClickListener() {
71 public void onClick(View v
) {
72 Toast
.makeText(activity
, group
.string
, Toast
.LENGTH_SHORT
).show();
76 ((TextView
) convertView
).setText(group
.string
);
82 public int getChildrenCount(int groupPosition
) {
83 return groups
.get(groupPosition
).children
.size();
87 public Object
getGroup(int groupPosition
) {
88 return groups
.get(groupPosition
);
92 public int getGroupCount() {
97 public void onGroupCollapsed(int groupPosition
) {
98 super.onGroupCollapsed(groupPosition
);
102 public void onGroupExpanded(int groupPosition
) {
103 super.onGroupExpanded(groupPosition
);
107 public long getGroupId(int groupPosition
) {
112 public boolean hasStableIds() {
117 public boolean isChildSelectable(int groupPosition
, int childPosition
) {