Hello Everyone,
Happy 2013
At the moment I have a simple list view which is feeded by a
SimpleCursorAdapter. Now I want to expand the list view with a few
sections. So i altered my query for my cursorAdapter and added some
groupBy's.
I got a bit further and i was told to use a BaseExpandableListAdapter. So I
found a few tutorials and created my own adapter based on
the BaseExpandableListAdapter. i have attached my code.
Now how do i go on to feed this adapter with data from my sqlite db?
Thanks very much
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package com.sanders.shechita.adapter;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import com.sanders.shechita.R;
import com.sanders.shechita.classes.ExpandListChild;
import com.sanders.shechita.classes.ExpandListGroup;
public class SlachtListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<ExpandListGroup> groups;
public SlachtListAdapter(Context context, ArrayList<ExpandListGroup> groups){
this.context = context;
this.groups = groups;
}
public void addItem(ExpandListChild item, ExpandListGroup group){
if(!groups.contains(group)){
groups.add(group);
}
int index = groups.indexOf(group);
ArrayList<ExpandListChild> ch = groups.get(index).getItems();
ch.add(item);
groups.get(index).setItems(ch);
}
public Object 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 View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view , ViewGroup parent){
ExpandListChild child = (ExpandListChild) getChild(groupPosition, childPosition);
if(view == null){
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.expandlist_child_item, null);
}
TextView tv = (TextView) view.findViewById(R.id.tvChild);
tv.setText(child.getName().toString());
tv.setTag(child.getTag());
return view;
}
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 View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent){
ExpandListGroup group = (ExpandListGroup) getGroup(groupPosition);
if(view == null){
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.expandlist_group_item, null);
}
TextView tv = (TextView) view.findViewById(R.id.tvGroup);
tv.setText(group.getName());
return view;
}
public boolean hasStableIds(){
return true;
}
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}