Paste
Pasted as Java by Khan ( 13 years ago )
package DiscountOn.App;
import java.util.ArrayList;
import android.content.Context;
import android.text.Html;
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.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
public class ColorAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<String> groups;
private ArrayList<ArrayList<String>> colors;
private LayoutInflater inflater;
ArrayList<ArrayList<Boolean>> check_states;
public ColorAdapter(Context context,
ArrayList<String> groups,
ArrayList<ArrayList<String>> colors, ArrayList<ArrayList<Boolean>> state ) {
this.context = context;
this.groups = groups;
this.colors = colors;
this.check_states=state;
inflater = LayoutInflater.from( context );
}
public Object getChild(int groupPosition, int childPosition) {
return colors.get( groupPosition ).get( childPosition );
}
public long getChildId(int groupPosition, int childPosition) {
return (long)( groupPosition*1024+childPosition ); // Max 1024 children per group
}
public View getChildView(int groupPosition,int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate(R.layout.child_row, parent, false);
String c = (String)getChild( groupPosition, childPosition );
final int grpPos = groupPosition;
final int childPos = childPosition;
TextView color = (TextView)v.findViewById( R.id.childname );
if( color != null )
color.setText(Html.fromHtml(c));
CheckBox cb = (CheckBox)v.findViewById(R.id.check1);
if(check_states.get(groupPosition).get(childPosition))
cb.setChecked(true);
else
cb.setChecked(false);
//cb.setChecked( ((Color) c).getState() );
v.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(check_states.get(grpPos).get(childPos))
check_states.get(grpPos).set(childPos,false);
Log.d("done","hi");
}
});
return v;
}
protected class ViewHolder {
protected TextView title;
protected CheckBox checkBox;
}
public int getChildrenCount(int groupPosition) {
return colors.get( groupPosition ).size();
}
public Object getGroup(int groupPosition) {
return groups.get( groupPosition );
}
public int getGroupCount() {
return groups.size();
}
public long getGroupId(int groupPosition) {
return (long)( groupPosition*1024 ); // To be consistent with getChildId
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate(R.layout.group_row, parent, false);
String gt = (String)getGroup( groupPosition );
TextView colorGroup = (TextView)v.findViewById( R.id.groupname );
if( gt != null )
colorGroup.setText(Html.fromHtml(gt));
return v;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void onGroupCollapsed (int groupPosition) {}
public void onGroupExpanded(int groupPosition) {}
}
Revise this Paste
Children: 51245