Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/LinearLayout1"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <include layout="@layout/titlebar" />
  8.  
  9. <ExpandableListView
  10. android:id="@+id/listView"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content"
  13. android:groupIndicator="@drawable/group_indicator" >
  14. </ExpandableListView>
  15.  
  16. </LinearLayout>
  17.  
  18. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  19.  
  20. <item android:drawable="@drawable/forward" android:state_empty="false"/>
  21. <item android:drawable="@android:color/transparent" android:state_empty="true"/>
  22. <item android:drawable="@drawable/back" android:state_selected="true"/>
  23.  
  24. </selector>
  25.  
  26. public class ExpandableListAdapter extends BaseExpandableListAdapter {
  27.  
  28. private final SparseArray<Group> groups;
  29. private LayoutInflater inflater;
  30.  
  31. public ExpandableListAdapter(Activity act, SparseArray<Group> groups) {
  32. activity = act;
  33. this.groups = groups;
  34. }
  35.  
  36. @Override
  37. public Object getChild(int groupPosition, int childPosition) {
  38. return groups.get(groupPosition).children.get(childPosition);
  39. }
  40.  
  41. @Override
  42. public long getChildId(int groupPosition, int childPosition) {
  43. return childPosition;
  44. }
  45.  
  46. @Override
  47. public View getChildView(int groupPosition, final int childPosition,
  48. boolean isLastChild, View convertView, ViewGroup parent) {
  49. final String children = (String) getChild(groupPosition, childPosition);
  50. TextView text = null;
  51. if (convertView == null) {
  52. convertView = inflater.inflate(R.layout.listrow_details, null);
  53. }
  54.  
  55. text = (TextView) convertView.findViewById(R.id.copyrightTextView);
  56. text.setText(Html.fromHtml(children));
  57.  
  58. return convertView;
  59. }
  60.  
  61. @Override
  62. public int getChildrenCount(int groupPosition) {
  63. return groups.get(groupPosition).children.size();
  64. }
  65.  
  66. @Override
  67. public Object getGroup(int groupPosition) {
  68. return groups.get(groupPosition);
  69. }
  70.  
  71. @Override
  72. public int getGroupCount() {
  73. return groups.size();
  74. }
  75.  
  76. @Override
  77. public void onGroupCollapsed(int groupPosition) {
  78. super.onGroupCollapsed(groupPosition);
  79. }
  80.  
  81. @Override
  82. public void onGroupExpanded(int groupPosition) {
  83. super.onGroupExpanded(groupPosition);
  84. }
  85.  
  86. @Override
  87. public long getGroupId(int groupPosition) {
  88. return groupPosition;
  89. }
  90.  
  91. @Override
  92. public View getGroupView(int groupPosition, boolean isExpanded,
  93. View convertView, ViewGroup parent) {
  94.  
  95. boolean isLinearLayout = groups.get(groupPosition).isLinearLayout();
  96.  
  97. if (convertView == null && isLinearLayout || isLinearLayout
  98. && !(convertView instanceof LinearLayout)) {
  99. convertView = inflater.inflate(groups.get(groupPosition)
  100. .getLinearLayoutId(), null);
  101.  
  102. }
  103. else if (convertView == null || !isLinearLayout
  104. && convertView instanceof LinearLayout) {
  105. convertView = inflater.inflate(R.layout.listrow_group, null);
  106. }
  107.  
  108. if (!(convertView instanceof LinearLayout)) {
  109. Group group = (Group) getGroup(groupPosition);
  110. ((CheckedTextView) convertView).setText(group.string);
  111. ((CheckedTextView) convertView).setChecked(isExpanded);
  112. }
  113. return convertView;
  114. }
  115.  
  116. @Override
  117. public boolean hasStableIds() {
  118. return false;
  119. }
  120.  
  121. @Override
  122. public boolean isChildSelectable(int groupPosition, int childPosition) {
  123. return groups.get(groupPosition).children.size() > 0;
  124. }
  125. }
  126.  
  127. public class ExpListAdapter extends BaseExpandableListAdapter {
  128. private Context context;
  129. private myServiceList = null;
  130. public ExpListAdapter(Context cxt) {
  131. this.context = cxt;
  132. myServiceList = MyUtils.GetServiceList(context);
  133. }
  134. @Override
  135. public Object getChild(int index, int childIndex) {
  136. return myServiceList.get(index);
  137. }
  138. @Override
  139. public long getChildId(int index, int childIndex) {
  140. return childIndex;
  141. }
  142. @Override
  143. public View getChildView(final int groupPosition, int childPosition,
  144. boolean isLastChild, View convertView, ViewGroup root) {
  145. if (convertView == null) {
  146. LayoutInflater inflater = (LayoutInflater) context
  147. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  148. convertView = inflater.inflate(R.layout.expendable_list_child, null);
  149. }
  150. // your child view code goes here
  151. return convertView;
  152. }
  153. @Override
  154. public int getChildrenCount(int arg0) {
  155. return 1;
  156. // I am keeping only on child in expandable list.
  157. // If you want you can make this dynamic too.
  158. }
  159. @Override
  160. public Object getGroup(int i) {
  161. if (myServiceList != null || i < myServiceList.getSize()) {
  162. return myServiceList.get(i).getDisplayName();
  163. }
  164. return "NOT FOUND";
  165. // Some group name
  166. }
  167. @Override
  168. public int getGroupCount() {
  169. if (myServiceList == null) {
  170. return 0;
  171. }
  172. return myServiceList.getSize();
  173. }
  174. @Override
  175. public long getGroupId(int i) {
  176. return i;
  177. }
  178. @Override
  179. public View getGroupView(int groupPosition, boolean isExpanded,
  180. View convertView, ViewGroup root) {
  181. LayoutInflater inflater = (LayoutInflater) context
  182. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  183. if (convertView == null) {
  184. convertView = inflater.inflate(R.layout.expendable_item, root,
  185. false);
  186. }
  187. // your code goes here
  188.  
  189. // This is what you asked for in your question
  190. ImageView imExpandableIndicator = (ImageView) convertView
  191. .findViewById(R.id.imv_expmain_indicator);
  192. if (isExpanded) {
  193. //set the indicator when expandable list is in expanded form
  194. imExpandableIndicator.setImageResource(R.drawable.uparrow);
  195. } else {
  196. //set the indicator when expandable list is not in expanded form
  197. imExpandableIndicator.setImageResource(R.drawable.downarrow);
  198. }
  199. // rest of your code if any
  200. return convertView;
  201. }
  202. @Override
  203. public boolean hasStableIds() {
  204. // TODO Auto-generated method stub
  205. return false;
  206. }
  207. @Override
  208. public boolean isChildSelectable(int arg0, int arg1) {
  209. // TODO Auto-generated method stub
  210. return true;
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement