Advertisement
Guest User

ExpandListAdapterTodays

a guest
Oct 9th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. package com.sentaca.android.accordion.adapter;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.util.Log;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.Button;
  12. import android.widget.TextView;
  13.  
  14. import com.sentaca.android.accordion.R;
  15. import com.sentaca.android.accordion.classes.ExpandListChild;
  16. import com.sentaca.android.accordion.classes.ExpandListGroup;
  17. import com.sentaca.android.accordion.classes.listeners.OrderOnClick;
  18. import com.sentaca.android.accordion.classes.listeners.VoteOnClick;
  19.  
  20. public class ExpandListAdapterTodays extends ExpandListAdapter {   
  21.     private Context context;
  22.     private ArrayList<ExpandListGroup> groups;
  23.    
  24.     public ExpandListAdapterTodays(Context context, ArrayList<ExpandListGroup> groups) {
  25.         super(context, groups);
  26.         this.context = context;
  27.         this.groups = groups;
  28.     }
  29.    
  30.     //Static class view holder
  31.     static class ViewHolder {
  32.         protected Button oBut;
  33.         protected Button vBut;
  34.         protected TextView description;
  35.     }
  36.  
  37.     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  38.         //Getting the appropriate child for the group and position
  39.         ExpandListChild child = (ExpandListChild) getChild(groupPosition, childPosition);
  40.        
  41.         View view = null;
  42.        
  43.         //Set up if doesn't exist
  44.         if (convertView == null) {
  45.             Log.d("OnClickListener", "groupPosition: " + groupPosition + " childPosition: " + childPosition);
  46.             Log.d("OnClickListener", "View being set up for: " + child.getName() + " desc: " + child.getDescription());
  47.            
  48.             LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
  49.             view = infalInflater.inflate(R.layout.expandlist_child_item_todays, null);
  50.            
  51.             //Attempt at viewholder
  52.             final ViewHolder holder = new ViewHolder();
  53.             holder.description = (TextView) view.findViewById(R.id.mealDescription);
  54.             holder.vBut = (Button)view.findViewById(R.id.vote);
  55.             holder.oBut = (Button)view.findViewById(R.id.order);
  56.            
  57.             view.setTag(holder);
  58.         }
  59.         else {
  60.             view = convertView;
  61.         }
  62.  
  63.         ViewHolder holder = (ViewHolder) view.getTag();
  64.        
  65.         holder.description.setText(child.getDescription());
  66.         holder.description.setTag(child.getTag());
  67.        
  68.         holder.oBut.setOnClickListener(new OrderOnClick(groups, (Activity)context, holder.oBut, view, child));
  69.         holder.vBut.setOnClickListener(new VoteOnClick(groups, (Activity)context, holder.vBut, view, child));
  70.        
  71.         return view;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement