Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sentaca.android.accordion.adapter;
- import java.util.ArrayList;
- import android.app.Activity;
- import android.content.Context;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.BaseExpandableListAdapter;
- import android.widget.Button;
- import android.widget.TextView;
- import com.sentaca.android.accordion.R;
- import com.sentaca.android.accordion.classes.ExpandListChild;
- import com.sentaca.android.accordion.classes.ExpandListGroup;
- public abstract class ExpandListAdapter extends BaseExpandableListAdapter {
- private Context context;
- private ArrayList<ExpandListGroup> groups;
- private Activity parent;
- /**
- * Abstract function that will be implemented in the sub classes
- */
- public abstract View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent);
- public ExpandListAdapter(Context context, ArrayList<ExpandListGroup> groups) {
- this.context = context;
- this.groups = groups;
- parent = (Activity) context;
- }
- public void addItem(ExpandListChild item, ExpandListGroup group) {
- //If it doesn't exist. Add it to the list.
- if (!groups.contains(group)) {
- groups.add(group);
- group.setItems(new ArrayList<ExpandListChild>());
- }
- //Then grab the index of the group that you just added.
- int index = groups.indexOf(group);
- //Update the groups list of items
- ArrayList<ExpandListChild> ch = groups.get(index).getItems();
- ch.add(item);
- groups.get(index).setItems(ch);
- }
- public ExpandListChild getChild(int groupPosition, int childPosition) {
- ArrayList<ExpandListChild> chList = groups.get(groupPosition).getItems();
- return chList.get(childPosition);
- }
- public long getChildId(int groupPosition, int childPosition) {
- return childPosition;
- }
- public int getChildrenCount(int groupPosition) {
- ArrayList<ExpandListChild> chList = groups.get(groupPosition).getItems();
- return chList.size();
- }
- public Object getGroup(int groupPosition) {
- return groups.get(groupPosition);
- }
- public int getGroupCount() {
- return groups.size();
- }
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
- public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) {
- ExpandListGroup group = (ExpandListGroup) getGroup(groupPosition);
- if (view == null) {
- LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
- view = inf.inflate(R.layout.expandlist_group_item, null);
- }
- Log.d("MyDebugStatements", group.getName());
- //Change the groups name to the appropriate string to be displayed
- TextView tv = (TextView) view.findViewById(R.id.tvGroup);
- tv.setText(group.getName());
- return view;
- }
- public boolean hasStableIds() {
- return true;
- }
- public boolean isChildSelectable(int arg0, int arg1) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement