Advertisement
kusha45

Exp List view

Mar 12th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.31 KB | None | 0 0
  1. package com.expList;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.graphics.Color;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.BaseExpandableListAdapter;
  10. import android.widget.ExpandableListAdapter;
  11. import android.widget.ExpandableListView;
  12. import android.widget.ImageView;
  13. import android.widget.LinearLayout;
  14. import android.widget.TextView;
  15.  
  16. public class ExpList extends Activity {
  17.     /** Called when the activity is first created. */
  18.     @Override
  19.     public void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.main);
  22.        
  23.         ExpandableListAdapter mAdapter;
  24.         ExpandableListView epView = (ExpandableListView) findViewById(R.id.ExpandableListView01);
  25.         mAdapter = new ExampleAdapter(this);
  26.         epView.setAdapter(mAdapter);
  27.        
  28.         //setListAdapter(new ExampleAdapter(this));  
  29.     }
  30.    
  31.     private class ExampleAdapter extends BaseExpandableListAdapter {
  32.         private Context context;
  33.         public ExampleAdapter(Context context) {
  34.             this.context = context;
  35.         }
  36.        
  37.         @Override
  38.         public Object getChild(int groupPosition, int childPosition) {
  39.             return null;
  40.         }
  41.         @Override
  42.         public long getChildId(int groupPosition, int childPosition) {
  43.             return 0;
  44.         }
  45.        
  46.         /**
  47.          *  getChildView overridden method will have responsibility of
  48.          *  constructing View for the child element when corresponding
  49.          *  group element is activated by click / touch action.
  50.          */
  51.          
  52.         @Override
  53.         public View getChildView(int groupPosition, int childPosition,
  54.                 boolean isLastChild, View convertView, ViewGroup parent) {
  55.             LinearLayout linear = new LinearLayout(this.context);
  56.             ImageView imView1 = null;
  57.             ImageView imView2 = null;
  58.             ImageView imView3 = null;
  59.             ImageView imView4 = null;
  60.            
  61.             if(groupPosition == 0) {
  62.                 imView1 = new ImageView(this.context);
  63.                 imView1.setImageResource(R.drawable.icon);
  64.                 imView2 = new ImageView(this.context);
  65.                 imView2.setImageResource(R.drawable.icon);
  66.                 imView3 = new ImageView(this.context);
  67.                 imView3.setImageResource(R.drawable.icon);
  68.                 imView4 = new ImageView(this.context);
  69.                 imView4.setImageResource(R.drawable.icon);
  70.                
  71.                 linear.addView(imView1);
  72.                 linear.addView(imView2);
  73.                 linear.addView(imView3);
  74.                 linear.addView(imView4);               
  75.             }
  76.            
  77.             if(groupPosition == 1) {
  78.                 imView1 = new ImageView(this.context);
  79.                 imView1.setImageResource(R.drawable.icon);
  80.                 imView2 = new ImageView(this.context);
  81.                 imView2.setImageResource(R.drawable.icon);
  82.                 imView3 = new ImageView(this.context);
  83.                 imView3.setImageResource(R.drawable.icon);
  84.                 imView4 = new ImageView(this.context);
  85.                 imView4.setImageResource(R.drawable.icon);
  86.                
  87.                 linear.addView(imView1);
  88.                 linear.addView(imView2);
  89.                 linear.addView(imView3);
  90.                 linear.addView(imView4);               
  91.             }
  92.             return linear;
  93.         }
  94.         @Override
  95.         public int getChildrenCount(int groupPosition) {
  96.             return 1;
  97.         }
  98.         @Override
  99.         public Object getGroup(int groupPosition) {
  100.             return null;
  101.         }
  102.         @Override
  103.         public int getGroupCount() {
  104.             return 2;
  105.         }
  106.        
  107.         @Override
  108.         public long getGroupId(int groupPosition) {
  109.             return 0;
  110.         }
  111.        
  112.         @Override
  113.         public View getGroupView(int groupPosition, boolean isExpanded,
  114.                 View convertView, ViewGroup parent) {
  115.             LinearLayout linear = new LinearLayout(this.context);
  116.             ImageView imView = null;
  117.             if(groupPosition == 0) {
  118.                 TextView txtView = new TextView(this.context);
  119.                 txtView.setText("Cup Board :");
  120.                 txtView.setTextColor(Color.BLACK);
  121.                 linear.addView(txtView);
  122.                 imView = new ImageView(this.context);
  123.                 imView.setImageResource(R.drawable.icon);
  124.                 linear.addView(imView);
  125.             }
  126.             if(groupPosition == 1) {
  127.                 TextView txtView = new TextView(this.context);
  128.                 txtView.setText("Cameras :");
  129.                 txtView.setTextColor(Color.BLACK);
  130.                 linear.addView(txtView);
  131.                 imView = new ImageView(this.context);
  132.                 imView.setImageResource(R.drawable.icon);
  133.                 linear.addView(imView);
  134.             }
  135.             return linear;
  136.         }
  137.         @Override
  138.         public boolean hasStableIds() {
  139.             return false;
  140.         }
  141.         @Override
  142.         public boolean isChildSelectable(int groupPosition, int childPosition) {
  143.             return true;
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement