Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. public class CustomGrid extends BaseAdapter {
  2.  
  3. private Context mContext;
  4. private final String[] web;
  5. private final int[] Imageid;
  6. public CustomGrid(Context c,String[] web,int[] Imageid ) {
  7. mContext = c;
  8. this.Imageid = Imageid;
  9. this.web = web;
  10. }
  11. @Override
  12. public int getCount() {
  13. // TODO Auto-generated method stub
  14. return web.length;
  15. }
  16. @Override
  17. public Object getItem(int position) {
  18. // TODO Auto-generated method stub
  19. return null;
  20. }
  21. @Override
  22. public long getItemId(int position) {
  23. // TODO Auto-generated method stub
  24. return 0;
  25. }
  26. @Override
  27. public View getView(int position, View convertView, ViewGroup parent) {
  28. // TODO Auto-generated method stub
  29. View grid;
  30. LayoutInflater inflater = (LayoutInflater) mContext
  31. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  32. if (convertView == null) {
  33. grid = new View(mContext);
  34. grid = inflater.inflate(R.layout.grid_single, null);
  35. TextView textView = (TextView) grid.findViewById(R.id.grid_text);
  36. ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
  37. textView.setText(web[position]);
  38. imageView.setImageResource(Imageid[position]);
  39. } else {
  40. grid = (View) convertView;
  41. }
  42. return grid;
  43. }
  44. }
  45.  
  46. public class SectionListAdapter extends BaseExpandableListAdapter {
  47. private Context context;
  48. private LayoutInflater inflater;
  49. private List<Section> sections;
  50.  
  51. String[] web = {
  52. "Language",
  53. "Add to Favorite",
  54.  
  55. } ;
  56. int[] imageId = {
  57. R.drawable.language,
  58. R.drawable.ic_action_favorite,
  59.  
  60. };
  61.  
  62. public SectionListAdapter(Context context, List<Section> sections) {
  63. this.sections = sections;
  64. this.inflater = LayoutInflater.from(context);
  65. this.context = context;
  66. }
  67.  
  68. @Override
  69. public Object getChild(int groupPosition, int childPosition) {
  70. return sections.get(groupPosition).getSectionItems().get(childPosition);
  71. }
  72.  
  73. @Override
  74. public long getChildId(int groupPosition, int childPosition) {
  75. return sections.get(groupPosition).getSectionItems().get(childPosition).getId();
  76. }
  77.  
  78. @Override
  79. public int getChildrenCount(int groupPosition) {
  80. return sections.get(groupPosition).getSectionItems().size();
  81. }
  82.  
  83. @Override
  84. public Object getGroup(int groupPosition) {
  85. return this.sections.get(groupPosition);
  86. }
  87.  
  88. @Override
  89. public int getGroupCount() {
  90. return this.sections.size();
  91. }
  92.  
  93. @Override
  94. public long getGroupId(int groupPosition) {
  95. return groupPosition;
  96. }
  97.  
  98. @Override
  99. public boolean hasStableIds() {
  100. return true;
  101. }
  102.  
  103. @Override
  104. public boolean isChildSelectable(int groupPosition, int childPosition) {
  105. return true;
  106. }
  107.  
  108. @Override
  109. public View getGroupView(int groupPosition, boolean isExpanded,
  110. View convertView, ViewGroup parent) {
  111. if (convertView == null) {
  112. convertView = inflater.inflate(R.layout.menu_sectionview,
  113. parent, false);
  114. }
  115.  
  116. TextView textView = (TextView) convertView
  117. .findViewById(R.id.slidingmenu_section_title);
  118. textView.setText(((Section) getGroup(groupPosition)).getTitle());
  119.  
  120. return convertView;
  121. }
  122.  
  123. @Override
  124. public View getChildView(int groupPosition, int childPosition,
  125. boolean isLastChild, View convertView, ViewGroup parent) {
  126.  
  127. ViewGroup item = getChildViewGroup(convertView, parent);
  128. GridView grid = (GridView) item.findViewById(R.id.grid);
  129.  
  130. CustomGrid adapter = new CustomGrid(parent.getContext(), web, imageId);
  131. grid.setAdapter(adapter);
  132. grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  133. @Override
  134. public void onItemClick(AdapterView<?> parent, View view,
  135. int position, long id) {
  136. Toast.makeText(parent.getContext(), "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
  137. }
  138. });
  139. return item;
  140. }
  141.  
  142.  
  143.  
  144. private ViewGroup getChildViewGroup(View convertView, ViewGroup parent) {
  145. if (convertView instanceof ViewGroup)
  146. {
  147. return (ViewGroup) convertView;
  148. }
  149. Context context = parent.getContext();
  150. LayoutInflater inflater = LayoutInflater.from(context);
  151. ViewGroup item = (ViewGroup) inflater.inflate(R.layout.menu_sectionitem, parent, false);;
  152. return item;
  153. }
  154.  
  155. public static Drawable getDrawableByName( String name, Context context ) {
  156. int drawableResource = context.getResources().getIdentifier(
  157. name,
  158. "drawable",
  159. context.getPackageName());
  160. if ( drawableResource == 0 ) {
  161. throw new RuntimeException("Can't find drawable with name: " + name );
  162. }
  163. return context.getResources().getDrawable(drawableResource);
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement