Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/LinearLayout1"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <include layout="@layout/titlebar" />
- <ExpandableListView
- android:id="@+id/listView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:groupIndicator="@drawable/group_indicator" >
- </ExpandableListView>
- </LinearLayout>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/forward" android:state_empty="false"/>
- <item android:drawable="@android:color/transparent" android:state_empty="true"/>
- <item android:drawable="@drawable/back" android:state_selected="true"/>
- </selector>
- public class ExpandableListAdapter extends BaseExpandableListAdapter {
- private final SparseArray<Group> groups;
- private LayoutInflater inflater;
- public ExpandableListAdapter(Activity act, SparseArray<Group> groups) {
- activity = act;
- this.groups = groups;
- }
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- return groups.get(groupPosition).children.get(childPosition);
- }
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- return childPosition;
- }
- @Override
- public View getChildView(int groupPosition, final int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- final String children = (String) getChild(groupPosition, childPosition);
- TextView text = null;
- if (convertView == null) {
- convertView = inflater.inflate(R.layout.listrow_details, null);
- }
- text = (TextView) convertView.findViewById(R.id.copyrightTextView);
- text.setText(Html.fromHtml(children));
- return convertView;
- }
- @Override
- public int getChildrenCount(int groupPosition) {
- return groups.get(groupPosition).children.size();
- }
- @Override
- public Object getGroup(int groupPosition) {
- return groups.get(groupPosition);
- }
- @Override
- public int getGroupCount() {
- return groups.size();
- }
- @Override
- public void onGroupCollapsed(int groupPosition) {
- super.onGroupCollapsed(groupPosition);
- }
- @Override
- public void onGroupExpanded(int groupPosition) {
- super.onGroupExpanded(groupPosition);
- }
- @Override
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
- boolean isLinearLayout = groups.get(groupPosition).isLinearLayout();
- if (convertView == null && isLinearLayout || isLinearLayout
- && !(convertView instanceof LinearLayout)) {
- convertView = inflater.inflate(groups.get(groupPosition)
- .getLinearLayoutId(), null);
- }
- else if (convertView == null || !isLinearLayout
- && convertView instanceof LinearLayout) {
- convertView = inflater.inflate(R.layout.listrow_group, null);
- }
- if (!(convertView instanceof LinearLayout)) {
- Group group = (Group) getGroup(groupPosition);
- ((CheckedTextView) convertView).setText(group.string);
- ((CheckedTextView) convertView).setChecked(isExpanded);
- }
- return convertView;
- }
- @Override
- public boolean hasStableIds() {
- return false;
- }
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return groups.get(groupPosition).children.size() > 0;
- }
- }
- public class ExpListAdapter extends BaseExpandableListAdapter {
- private Context context;
- private myServiceList = null;
- public ExpListAdapter(Context cxt) {
- this.context = cxt;
- myServiceList = MyUtils.GetServiceList(context);
- }
- @Override
- public Object getChild(int index, int childIndex) {
- return myServiceList.get(index);
- }
- @Override
- public long getChildId(int index, int childIndex) {
- return childIndex;
- }
- @Override
- public View getChildView(final int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup root) {
- if (convertView == null) {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.expendable_list_child, null);
- }
- // your child view code goes here
- return convertView;
- }
- @Override
- public int getChildrenCount(int arg0) {
- return 1;
- // I am keeping only on child in expandable list.
- // If you want you can make this dynamic too.
- }
- @Override
- public Object getGroup(int i) {
- if (myServiceList != null || i < myServiceList.getSize()) {
- return myServiceList.get(i).getDisplayName();
- }
- return "NOT FOUND";
- // Some group name
- }
- @Override
- public int getGroupCount() {
- if (myServiceList == null) {
- return 0;
- }
- return myServiceList.getSize();
- }
- @Override
- public long getGroupId(int i) {
- return i;
- }
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup root) {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- if (convertView == null) {
- convertView = inflater.inflate(R.layout.expendable_item, root,
- false);
- }
- // your code goes here
- // This is what you asked for in your question
- ImageView imExpandableIndicator = (ImageView) convertView
- .findViewById(R.id.imv_expmain_indicator);
- if (isExpanded) {
- //set the indicator when expandable list is in expanded form
- imExpandableIndicator.setImageResource(R.drawable.uparrow);
- } else {
- //set the indicator when expandable list is not in expanded form
- imExpandableIndicator.setImageResource(R.drawable.downarrow);
- }
- // rest of your code if any
- return convertView;
- }
- @Override
- public boolean hasStableIds() {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean isChildSelectable(int arg0, int arg1) {
- // TODO Auto-generated method stub
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement