public static void setExpandedListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) { ExpandableListAdapter listAdapter = listView.getExpandableListAdapter(); if (listAdapter == null) { return; } View listItem = listAdapter.getChildView(groupPosition, 0, true, null, listView); listItem.measure(0, 0); int appendHeight = 0; for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) { appendHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height += appendHeight; listView.setLayoutParams(params); }
public static void setCollapseListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) { ExpandableListAdapter listAdapter = listView.getExpandableListAdapter(); if (listAdapter == null) { return; } View listItem = listAdapter.getChildView(groupPosition, 0, true, null, listView); listItem.measure(0, 0); int appendHeight = 0; for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) { appendHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height -= appendHeight; listView.setLayoutParams(params); }
private ArrayList<Long> getExpandedIds() { ExpandableListView list = mList; ExpandableListAdapter adapter = mAdapter; if (adapter != null) { int length = adapter.getGroupCount(); ArrayList<Long> expandedIds = new ArrayList<Long>(); for(int i=0; i < length; i++) { if(list.isGroupExpanded(i)) { expandedIds.add(adapter.getGroupId(i)); } } return expandedIds; } else { return null; } }
/** * Sets the adapter that provides data to this view. * * @param adapter The adapter that provides data to this view. */ public void setAdapter( ExpandableListAdapter adapter ) { // Set member variable mAdapter = adapter; if( adapter != null ) { // Create the connector mConnector = new ExpandableHListConnector( adapter ); } else { mConnector = null; } // Link the ListView (superclass) to the expandable list data through the connector super.setAdapter( mConnector ); }
@Override public void setAdapter(ExpandableListAdapter adapter) { super.setAdapter(adapter); mAdapter = adapter; mHeaderView = adapter.getGroupView(0, false, null, this); boolean isBaseAdapter = adapter instanceof BaseExpandableListAdapter; if (cacheHeaderViews == null) { if (isBaseAdapter) { int typeCount = ((BaseExpandableListAdapter) adapter).getGroupTypeCount(); cacheHeaderViews = new SparseArray<>(typeCount); } cacheHeaderViews = new SparseArray<>(1); } if (mHeaderView != null) { int groupType = 0; if (isBaseAdapter) { groupType = ((BaseExpandableListAdapter) adapter).getGroupType(0); cacheHeaderViews.put(groupType, mHeaderView); } cacheHeaderViews.put(groupType, mHeaderView); } }
public void setExpandableListAdapter(ExpandableListAdapter adapter){ mAdapter=null; boolean hadAdapter = mExpandableListAdapter != null; mExpandableListAdapter = adapter; if (mList!=null && !(mList instanceof ExpandableListView)){ changeListView(true); } if (mList instanceof ExpandableListView) { ((ExpandableListView)mList).setAdapter(adapter); if (!mListShown && !hadAdapter) { // The list was hidden, and previously didn't have an // adapter. It is now time to show it. setListShown(true, getView().getWindowToken() != null); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.frament_all_list, null); this.list = (ExpandableListView) view.findViewById(R.id.expandableListView1); this.list.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { ExpandableListAdapter adapter = parent.getExpandableListAdapter(); MyActivityInfo info = (MyActivityInfo)adapter.getChild(groupPosition, childPosition); LauncherIconCreator.launchActivity(getActivity(), info.component_name); return false; } }); AllTasksListAsyncProvider provider = new AllTasksListAsyncProvider(this.getActivity(), this); provider.execute(); return view; }
private void clearDataAndShowLoadingIndicator() { if (mProgressIndicator != null) { mNonExpandableListView.setEmptyView(null); mNonExpandableListView.setVisibility(View.GONE); mNonExpandableListView.setOnItemClickListener(null); mNonExpandableListView.setAdapter(null); mExpandableListView.setEmptyView(null); mExpandableListView.setVisibility(View.GONE); mExpandableListView.setOnChildClickListener(null); mExpandableListView.setAdapter((ExpandableListAdapter) null); mEmptyMessage.setVisibility(View.GONE); mCustomErrorText.setVisibility(View.GONE); mProgressIndicator.setVisibility(View.VISIBLE); } mLoadedData = null; }
@Override public void setAdapter(final ExpandableListAdapter adapter){ if (adapter == null) throw new NullPointerException("The adapter you passed was null"); if (adapter instanceof MultiChoiceExpandableAdapter) this.mAdapterWrapper = (MultiChoiceExpandableAdapter) adapter; else if (mAdapterWrapper == null) mAdapterWrapper = new MultiChoiceExpandableAdapter( adapter, this); else mAdapterWrapper.setWrappedAdapter(adapter); super.setAdapter(mAdapterWrapper); mCheckStore = new CheckStateStore(this); // Must do this to ensure // hasStableIds stays // current }
public void expandGroups(long[] groupsToExpand) { // this.expandedIds = expandedIds; if (groupsToExpand != null && groupsToExpand.length > 0) { ExpandableListAdapter adapter = getExpandableListAdapter(); if (adapter != null) { for (int i = 0; i < adapter.getGroupCount(); i++) { long id = adapter.getGroupId(i); if (inArray(groupsToExpand, id)) { expandGroup(i); } } } } }
private void selectChildView(ExpandableListView expandLV, int groupPosition, int childPosition, boolean force) { if (groupPosition < mAdapter.getGroupCount() && childPosition < mAdapter.getChildrenCount(groupPosition)) { // a task instance element has been clicked, get it's instance id and notify the activity ExpandableListAdapter listAdapter = expandLV.getExpandableListAdapter(); Cursor cursor = (Cursor) listAdapter.getChild(groupPosition, childPosition); if (cursor == null) { return; } // TODO: for now we get the id of the task, not the instance, once we support recurrence we'll have to change that Long selectTaskId = cursor.getLong(cursor.getColumnIndex(Instances.TASK_ID)); if (selectTaskId != null) { // Notify the active callbacks interface (the activity, if the fragment is attached to one) that an item has been selected. // TODO: use the instance URI one we support recurrence Uri taskUri = ContentUris.withAppendedId(Tasks.getContentUri(mAuthority), selectTaskId); mCallbacks.onItemSelected(taskUri, force, mInstancePosition); } } }
private void restoreExpandedState(ArrayList<Long> expandedIds) { this.expandedIds = expandedIds; if (expandedIds != null) { ExpandableListView list = mList; ExpandableListAdapter adapter = mAdapter; if (adapter != null) { for (int i=0; i<adapter.getGroupCount(); i++) { long id = adapter.getGroupId(i); if (expandedIds.contains(id)) list.expandGroup(i); } } } }
public KeyValueView(Context context, KVSaver kvSaver) { super(context); this.kvSaver = kvSaver; inflate(context, R.layout.view_keyvalue, this); listView = findViewById(R.id.list_keyvalue); adapter = new KeyValueAdapter(LayoutInflater.from(context)); listView.setAdapter((ExpandableListAdapter) adapter); updateData(); kvSaver.addObserver(this); }
/** * Provide the adapter for the expandable list. */ public void setListAdapter(ExpandableListAdapter adapter) { synchronized (this) { ensureList(); mAdapter = adapter; mList.setAdapter(adapter); } }
/** * Provide the adapter for the expandable list. */ void setListAdapter(ExpandableListAdapter adapter) { synchronized (this) { ensureList(); mAdapter = adapter; mList.setAdapter(adapter); } }
/** * Provide the cursor for the list view. */ void setListAdapter(ExpandableListAdapter adapter) { boolean hadAdapter = mAdapter != null; mAdapter = adapter; if (mExpandableList != null) { mExpandableList.setAdapter(adapter); if (!mExpandableListShown && !hadAdapter) { // The list was hidden, and previously didn't have an // adapter. It is now time to show it. View v = getView(); if (v != null) setListShown(true, getView().getWindowToken() != null); } } }
/** * @see ExpandableListView#setAdapter(ExpandableListAdapter) */ public void setAdapter(ExpandableListAdapter adapter) { super.setAdapter(adapter); // Make sure that the adapter extends AnimatedExpandableListAdapter if(adapter instanceof AnimatedExpandableListAdapter) { this.adapter = (AnimatedExpandableListAdapter) adapter; this.adapter.setParent(this); } else { throw new ClassCastException(adapter.toString() + " must implement AnimatedExpandableListAdapter"); } }
/** * Shows the popup that is opened when the user clicks on the info action button of a details page. * An {@link ExpandableListView} is used as a layout. * * @param context The context to show the popup in. * @param title The popup's title. * @param groups The expandable categories. * @param entries Each category in <code>groups</code> shows one entry when expanded. * @return The dialog. */ private static AlertDialog showDetailsInfo(Context context, String title, String[] groups, String[] entries, DialogInterface.OnClickListener onSubmitListener) { if (groups.length != entries.length) { throw new IllegalArgumentException(); } // Custom title TextView customTitle = (TextView) LayoutInflater.from(context).inflate(R.layout.popup_title, null); customTitle.setText(title); View popupDetailsInfo = LayoutInflater.from(context) .inflate(R.layout.popup_details_info, null); ExpandableListView listViewDetailsInfo = (ExpandableListView) popupDetailsInfo.findViewById(R.id.expandablelistview_popup_details_info); ExpandableListAdapter adapter = createDetailsInfoAdapter(context, groups, entries); listViewDetailsInfo.setAdapter(adapter); AlertDialog.Builder popupBuilder = new AlertDialog.Builder(context); popupBuilder.setView(popupDetailsInfo) .setNeutralButton(R.string.ok, onSubmitListener) .setCustomTitle(customTitle); AlertDialog dialog = popupBuilder.create(); dialog.show(); Utility.setFont(FontManager.Font.ROBOTO_LIGHT, new TextView[]{ customTitle }); return dialog; }
private static ExpandableListAdapter createDetailsInfoAdapter(Context context, String[] groups, String[] entries) { // Creates the upper list level List<Map<String, String>> groupData = new LinkedList<>(); String groupName = "GroupName"; String[] groupFrom = new String[] {groupName}; int[] groupTo = new int[] {R.id.component_details_info_group}; for (String g : groups) { Map<String, String> group = new HashMap<>(1); group.put(groupName, g); groupData.add(group); } // Creates the lower list level List<List<Map<String, String>>> childData = new LinkedList<>(); String groupContent = "Content"; String[] childFrom = new String[] {groupContent}; int[] childTo = new int[] {R.id.component_details_info_entry}; for (String e : entries) { List<Map<String, String>> content = new LinkedList<>(); Map<String, String> entry = new HashMap<>(1); entry.put(groupContent, e); content.add(entry); childData.add(content); } return new DetailsInfoAdapter(context, groupData, groupFrom, groupTo, childData, childFrom, childTo); }
/** * Sets ExpandableListView height dynamically based on the height of the items. * * @param expandablelistView to be resized * @return true if the expandablelistView is successfully resized, false otherwise */ public static boolean setListViewHeightBasedOnItems(ExpandableListView expandablelistView) { ExpandableListAdapter expandableListAdapter = expandablelistView.getExpandableListAdapter(); if (expandableListAdapter != null) { int numberOfGroups = expandableListAdapter.getGroupCount(); int numberOfDividers = numberOfGroups; // Get total height of all items of all group expanded int totalItemsHeight = 0; for (int groupPos = 0; groupPos < numberOfGroups; groupPos++) { View item = expandableListAdapter.getGroupView(groupPos, expandablelistView.isGroupExpanded(groupPos), null, expandablelistView); item.measure(0, 0); totalItemsHeight += item.getMeasuredHeight(); if(expandablelistView.isGroupExpanded(groupPos)) { totalItemsHeight += calculateHeightOfOneGroup(groupPos, expandableListAdapter, expandablelistView); numberOfDividers += expandableListAdapter.getChildrenCount(groupPos); } } // Get total height of all item dividers. int totalDividersHeight = expandablelistView.getDividerHeight() * numberOfDividers; // Set list height. ViewGroup.LayoutParams params = expandablelistView.getLayoutParams(); params.height = totalItemsHeight + totalDividersHeight + 5; expandablelistView.setLayoutParams(params); expandablelistView.requestLayout(); return true; } else { return false; } }
/** * Calculate the height of an expanded group dynamically based on the height of the items. * * @param groupPos position of the current group * @param expandableListAdapter adapter of the expandableList * @param parent the parent that this view will eventually be attached to * @return true if the listView is successfully resized, false otherwise */ public static int calculateHeightOfOneGroup(int groupPos, ExpandableListAdapter expandableListAdapter, ViewGroup parent) { int numberOfItems = expandableListAdapter.getChildrenCount(groupPos); // Get total height of all items in the group int totalItemsHeight = 0; for (int itemPos = 0; itemPos < numberOfItems; itemPos++) { boolean lastItem = false; if(itemPos == numberOfItems-1){ lastItem = true; } // Supprimer le if si on veut garder un truc générique. Ici, le if sert à gérer la cutom expandable en plus des expandables classiques View item; if(expandableListAdapter instanceof com.orange.ease.idunnololz.widgets.AnimatedExpandableListView.AnimatedExpandableListAdapter){ item = ((AnimatedExpandableListView.AnimatedExpandableListAdapter) expandableListAdapter).getRealChildView(groupPos, itemPos, lastItem, null, parent); }else{ item = expandableListAdapter.getChildView(groupPos, itemPos, lastItem, null, parent); } item.measure(0, 0); totalItemsHeight += item.getMeasuredHeight(); } return totalItemsHeight; }
private void onScrollStateChanged(ExpandableListView elv, int scrollState) { elv.setTag(AQuery.TAG_NUM, scrollState); if (scrollState == SCROLL_STATE_IDLE) { int first = elv.getFirstVisiblePosition(); int last = elv.getLastVisiblePosition(); int count = last - first; ExpandableListAdapter ela = elv.getExpandableListAdapter(); for (int i = 0; i <= count; i++) { long packed = elv.getExpandableListPosition(i + first); int group = ExpandableListView.getPackedPositionGroup(packed); int child = ExpandableListView.getPackedPositionChild(packed); if (group >= 0) { View convertView = elv.getChildAt(i); Long targetPacked = (Long) convertView.getTag(AQuery.TAG_NUM); if (targetPacked != null && targetPacked.longValue() == packed) { if (child == -1) { ela.getGroupView(group, elv.isGroupExpanded(group), convertView, elv); } else { ela.getChildView(group, child, child == ela.getChildrenCount(group) - 1, convertView, elv); } convertView.setTag(AQuery.TAG_NUM, null); } else { //AQUtility.debug("skip!"); } } } } }
/** * @see ExpandableListView#setAdapter(ExpandableListAdapter) */ public void setAdapter(ExpandableListAdapter adapter) { super.setAdapter(adapter); // Make sure that the adapter extends AnimatedExpandableListAdapter if (adapter instanceof AnimatedExpandableListAdapter) { this.adapter = (AnimatedExpandableListAdapter) adapter; this.adapter.setParent(this); } else { throw new ClassCastException(adapter.toString() + " must implement AnimatedExpandableListAdapter"); } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.actvity_show_inventory); // Get the listview ExpandableListView maListView = (ExpandableListView) findViewById(R.id.myListView); // Set datas ExpandableListAdapter monListAdapter = new ExpandableSectionAdapter(this, Inventory.getInstance(this).getAllSections()); // Set list adapter maListView.setAdapter(monListAdapter); }
@Override protected void onPostExecute(Cursor cursor) { ExpandableListAdapter ela = getExpandableListAdapter(); if (ela == null) { setListAdapter(new AlertTriggerCursorAdapter(cursor, context, false, mEditButtonListener)); } else { AlertTriggerCursorAdapter atca = (AlertTriggerCursorAdapter)getExpandableListAdapter(); atca.changeCursor(cursor); } }
/** * Provide the adapter for the expandable list. */ public void setListAdapter(final ExpandableListAdapter adapter){ final boolean hadAdapter = this.adapter != null; this.adapter = adapter; if(list != null){ list.setAdapter(adapter); if(!isListShown && !hadAdapter){ // The list was hidden, and previously didn't have an // adapter. It is now time to show it. setListShown(true, getView().getWindowToken() != null); } } }
/** * Provide the adapter for the expandable list. */ public void setListAdapter(ExpandableListAdapter adapter) { synchronized (this) { ensureLayout(); mAdapter = adapter; mList.setAdapter(adapter); } }
@Override public void setAdapter(ExpandableListAdapter adapter) { if (adapter instanceof SlideAdapter) { SlideAdapter slideAdapter = (SlideAdapter) adapter; slideAdapter.setSlideSupporter(mActionHandler); } super.setAdapter(adapter); }