Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.expList;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseExpandableListAdapter;
- import android.widget.ExpandableListAdapter;
- import android.widget.ExpandableListView;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- public class ExpList extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ExpandableListAdapter mAdapter;
- ExpandableListView epView = (ExpandableListView) findViewById(R.id.ExpandableListView01);
- mAdapter = new ExampleAdapter(this);
- epView.setAdapter(mAdapter);
- //setListAdapter(new ExampleAdapter(this));
- }
- private class ExampleAdapter extends BaseExpandableListAdapter {
- private Context context;
- public ExampleAdapter(Context context) {
- this.context = context;
- }
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- return null;
- }
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- return 0;
- }
- /**
- * getChildView overridden method will have responsibility of
- * constructing View for the child element when corresponding
- * group element is activated by click / touch action.
- */
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- LinearLayout linear = new LinearLayout(this.context);
- ImageView imView1 = null;
- ImageView imView2 = null;
- ImageView imView3 = null;
- ImageView imView4 = null;
- if(groupPosition == 0) {
- imView1 = new ImageView(this.context);
- imView1.setImageResource(R.drawable.icon);
- imView2 = new ImageView(this.context);
- imView2.setImageResource(R.drawable.icon);
- imView3 = new ImageView(this.context);
- imView3.setImageResource(R.drawable.icon);
- imView4 = new ImageView(this.context);
- imView4.setImageResource(R.drawable.icon);
- linear.addView(imView1);
- linear.addView(imView2);
- linear.addView(imView3);
- linear.addView(imView4);
- }
- if(groupPosition == 1) {
- imView1 = new ImageView(this.context);
- imView1.setImageResource(R.drawable.icon);
- imView2 = new ImageView(this.context);
- imView2.setImageResource(R.drawable.icon);
- imView3 = new ImageView(this.context);
- imView3.setImageResource(R.drawable.icon);
- imView4 = new ImageView(this.context);
- imView4.setImageResource(R.drawable.icon);
- linear.addView(imView1);
- linear.addView(imView2);
- linear.addView(imView3);
- linear.addView(imView4);
- }
- return linear;
- }
- @Override
- public int getChildrenCount(int groupPosition) {
- return 1;
- }
- @Override
- public Object getGroup(int groupPosition) {
- return null;
- }
- @Override
- public int getGroupCount() {
- return 2;
- }
- @Override
- public long getGroupId(int groupPosition) {
- return 0;
- }
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
- LinearLayout linear = new LinearLayout(this.context);
- ImageView imView = null;
- if(groupPosition == 0) {
- TextView txtView = new TextView(this.context);
- txtView.setText("Cup Board :");
- txtView.setTextColor(Color.BLACK);
- linear.addView(txtView);
- imView = new ImageView(this.context);
- imView.setImageResource(R.drawable.icon);
- linear.addView(imView);
- }
- if(groupPosition == 1) {
- TextView txtView = new TextView(this.context);
- txtView.setText("Cameras :");
- txtView.setTextColor(Color.BLACK);
- linear.addView(txtView);
- imView = new ImageView(this.context);
- imView.setImageResource(R.drawable.icon);
- linear.addView(imView);
- }
- return linear;
- }
- @Override
- public boolean hasStableIds() {
- return false;
- }
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement