Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 20th, 2011  |  syntax: Java  |  size: 5.65 KB  |  views: 135  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.android.xont.controller;
  2.  
  3. import android.app.Activity;
  4. import android.app.ExpandableListActivity;
  5. import android.app.ListActivity;
  6. import android.content.Intent;
  7. import android.graphics.drawable.Drawable;
  8. import android.os.Bundle;
  9. import android.view.Gravity;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.widget.AbsListView;
  14. import android.widget.AdapterView;
  15. import android.widget.ArrayAdapter;
  16. import android.widget.BaseExpandableListAdapter;
  17. import android.widget.ExpandableListAdapter;
  18. import android.widget.ExpandableListView;
  19. import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
  20. import android.widget.ListView;
  21. import android.widget.TextView;
  22. import android.widget.Toast;
  23. import android.widget.AdapterView.OnItemClickListener;
  24.  
  25. public class SettingScreenActivity extends ExpandableListActivity {
  26.         static final String[] SETTINGOPITONS = new String[] { "Theme",
  27.                         "Database Setup" };
  28.         private static Drawable sBackground;
  29.  
  30.         ExpandableListAdapter mAdapter;
  31.  
  32.         public void onCreate(Bundle savedInstanceState) {
  33.                 super.onCreate(savedInstanceState);
  34.                 sBackground =  getResources().getDrawable(R.drawable.wallpaper);
  35.        
  36.                
  37.                 // Set up our adapter
  38.                 mAdapter = new MyExpandableListAdapter();
  39.                 setListAdapter(mAdapter);
  40.                 getExpandableListView().setBackgroundDrawable(sBackground);
  41.                 getExpandableListView().setTextFilterEnabled(true);
  42.                 registerForContextMenu(getExpandableListView());
  43.  
  44.         }
  45.  
  46.         @Override
  47.         public boolean onContextItemSelected(MenuItem item) {
  48.                 ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
  49.  
  50.                 String title = ((TextView) info.targetView).getText().toString();
  51.  
  52.                 int type = ExpandableListView.getPackedPositionType(info.packedPosition);
  53.                 System.out.println(" ----- " + type);
  54.                 if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
  55.                         int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
  56.                         int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
  57.                         Toast.makeText(this,title + ": Child " + childPos + " clicked in group "+ groupPos, Toast.LENGTH_SHORT).show();
  58.                         return true;
  59.                 } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
  60.                         int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
  61.                         Toast.makeText(this, title + ": Group " + groupPos + " clicked",Toast.LENGTH_SHORT).show();
  62.                         return true;
  63.                 }
  64.  
  65.                 return false;
  66.         }
  67.        
  68.         @Override
  69.     public boolean onChildClick(ExpandableListView parent, View v,int gp, int cp, long id) {
  70.                 System.out.println(" ----- " + gp + "======= " + cp);
  71.                 if(gp == 1 && cp == 0){
  72.                         Intent showContent = new Intent(getApplicationContext(),CreateNormalDatabaseActivity.class);
  73.                         startActivity(showContent);
  74.                 }else{
  75.                         Intent showContent = new Intent(getApplicationContext(),CreateNormalDatabaseActivity.class);
  76.                         startActivity(showContent);
  77.                 }
  78.  
  79.         return super .onChildClick(parent, v, gp, cp, id);
  80.     }
  81.        
  82.         public class MyExpandableListAdapter extends BaseExpandableListAdapter {
  83.         // Sample data set.  children[i] contains the children (String[]) for groups[i].
  84.                 //static final String[] SETTINGOPITONS = new String[] { };
  85.         private String[] groups = { "Theme","Database Setup" ,"Synchronization","Change Password" };
  86.         private String[][] children = {
  87.                 { "Font Setting", "Backgroud Setting"},
  88.                 { "Master Database", "Normal Database"},
  89.                 { "Download", "Upload"},
  90.                 { ""}
  91.                
  92.         };
  93.        
  94.         public Object getChild(int groupPosition, int childPosition) {
  95.             return children[groupPosition][childPosition];
  96.         }
  97.  
  98.         public long getChildId(int groupPosition, int childPosition) {
  99.             return childPosition;
  100.         }
  101.  
  102.         public int getChildrenCount(int groupPosition) {
  103.             return children[groupPosition].length;
  104.         }
  105.  
  106.         public TextView getGenericView() {
  107.             // Layout parameters for the ExpandableListView
  108.             AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 64);
  109.  
  110.             TextView textView = new TextView(SettingScreenActivity.this);
  111.             textView.setLayoutParams(lp);
  112.             // Center the text vertically
  113.             textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
  114.             // Set the text starting position
  115.            
  116.             textView.setPadding(45, 13, 13, 13);
  117.             return textView;
  118.         }
  119.        
  120.         public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
  121.                 View convertView, ViewGroup parent) {
  122.             TextView textView = getGenericView();
  123.             textView.setText(getChild(groupPosition, childPosition).toString());
  124.             return textView;
  125.         }
  126.  
  127.         public Object getGroup(int groupPosition) {
  128.             return groups[groupPosition];
  129.         }
  130.  
  131.         public int getGroupCount() {
  132.             return groups.length;
  133.         }
  134.  
  135.         public long getGroupId(int groupPosition) {
  136.             return groupPosition;
  137.         }
  138.  
  139.         public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
  140.                 ViewGroup parent) {
  141.             TextView textView = getGenericView();
  142.             textView.setText(getGroup(groupPosition).toString());
  143.             return textView;
  144.         }
  145.  
  146.         public boolean isChildSelectable(int groupPosition, int childPosition) {
  147.             return true;
  148.         }
  149.  
  150.         public boolean hasStableIds() {
  151.             return true;
  152.         }
  153.  
  154.     }
  155. }
  156.  
  157.