@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); InputStream raw=getResources().openRawResource(R.raw.sample); BufferedReader in=new BufferedReader(new InputStreamReader(raw)); String str; StringBuffer buf=new StringBuffer(); try { while ((str=in.readLine()) != null) { buf.append(str); buf.append('\n'); } in.close(); JSONObject model=new JSONObject(buf.toString()); ExpandableListView elv=(ExpandableListView)findViewById(R.id.elv); adapter=new JSONExpandableListAdapter(getLayoutInflater(), model); elv.setAdapter(adapter); elv.setOnChildClickListener(this); elv.setOnGroupClickListener(this); elv.setOnGroupExpandListener(this); elv.setOnGroupCollapseListener(this); } catch (Exception e) { Log.e(getClass().getName(), "Exception reading JSON", e); } }
public void setOnGroupCollapseExpandListener(OnGroupCollapseExpandListener l) { mGroupCollapseExpandListener = l; if(mList != null) { mList.setOnGroupCollapseListener(l); mList.setOnGroupExpandListener(l); } }
/** * Method to initialize the listeners */ public void initListeners() { // ExpandableListView Group expanded listener expandableListView.setOnGroupExpandListener( new ExpandableListView.OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { Toast.makeText(getApplicationContext(), listDataGroup.get(groupPosition) + "Collapsed", Toast.LENGTH_SHORT).show(); } }); // ExpandableListView Group collapsed listener expandableListView.setOnGroupCollapseListener( new ExpandableListView.OnGroupCollapseListener() { @Override public void onGroupCollapse(int groupPosition) { Toast.makeText(getApplicationContext(), listDataGroup.get(groupPosition) + "Collapsed", Toast.LENGTH_SHORT).show(); } }); }
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() { @Override public void onGroupCollapse(int groupPosition) {
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.layout_expandable_list, null); mList = (ExpandableListView) v.findViewById(android.R.id.list); mEmptyView = (TextView) v.findViewById(android.R.id.empty); mList.setAdapter(mAdapter); mList.setOnGroupCollapseListener(mGroupCollapseExpandListener); mList.setOnGroupExpandListener(mGroupCollapseExpandListener); mList.setOnGroupClickListener(this); mList.setOnChildClickListener(this); if(mExpandAll) expandAllInternal(); mList.setEmptyView(mEmptyView); mEmptyView.setText(mEmptyViewTextResId); return v; }
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
/** * 初始化所有城市列表 */ public void initAllCityList() { // 扩展列表 View provinceContainer = LayoutInflater.from(OfflineMapActivity.this) .inflate(R.layout.offline_province_listview, null); mAllOfflineMapList = (ExpandableListView) provinceContainer .findViewById(R.id.province_download_list); initProvinceListAndCityMap(); adapter = new OfflineListAdapter(provinceList, amapManager, OfflineMapActivity.this); // 为列表绑定数据源 mAllOfflineMapList.setAdapter(adapter); // adapter实现了扩展列表的展开与合并监听 mAllOfflineMapList.setOnGroupCollapseListener(adapter); mAllOfflineMapList.setOnGroupExpandListener(adapter); mAllOfflineMapList.setGroupIndicator(null); }
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
/** * Updates the screen state (current list and other views) when the * content changes. * * @see Activity.onContentChanged() */ public void onContentChanged() { // super.onContentChanged(); View emptyView = getView().findViewById(android.R.id.empty); mExpandableList = (ExpandableListView) getView().findViewById(android.R.id.list); if (mExpandableList == null) { throw new RuntimeException( "Your content must have a ExpandableListView whose id attribute is " + "'android.R.id.list'"); } if (emptyView != null) { mExpandableList.setEmptyView(emptyView); } mExpandableList.setOnChildClickListener(this); mExpandableList.setOnGroupExpandListener(this); mExpandableList.setOnGroupCollapseListener(this); if (mFinishedStart) { setListAdapter(mAdapter); } mFinishedStart = true; }
mExpandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() { @Override public void onGroupCollapse(int groupPosition) {
mExpandalbeView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() { @Override public void onGroupCollapse(int groupPosition) {
/** * Constructor returns an instance of RecentTabsPage. * * @param activity The activity this view belongs to. * @param recentTabsManager The RecentTabsManager which provides the model data. */ public RecentTabsPage(Activity activity, RecentTabsManager recentTabsManager) { mActivity = activity; mRecentTabsManager = recentTabsManager; mTitle = activity.getResources().getString(R.string.recent_tabs); mThemeColor = ApiCompatibilityUtils.getColor( activity.getResources(), R.color.default_primary_color); mRecentTabsManager.setUpdatedCallback(this); LayoutInflater inflater = LayoutInflater.from(activity); mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null); mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview); mAdapter = buildAdapter(activity, recentTabsManager); mListView.setAdapter(mAdapter); mListView.setOnChildClickListener(this); mListView.setGroupIndicator(null); mListView.setOnGroupCollapseListener(this); mListView.setOnGroupExpandListener(this); mListView.setOnCreateContextMenuListener(this); mView.addOnAttachStateChangeListener(this); ApplicationStatus.registerStateListenerForActivity(this, activity); // {@link #mInForeground} will be updated once the view is attached to the window. onUpdated(); }
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
/** * Updates the screen state (current list and other views) when the content changes. * * @see android.support.v7.app.AppCompatActivity#onContentChanged() */ @Override public void onContentChanged() { super.onContentChanged(); View emptyView = findViewById(R.id.empty); mList = findViewById(R.id.list); if (mList == null) { throw new RuntimeException( "Your content must have a ExpandableListView whose id attribute is " + "'R.id.list'"); } if (emptyView != null) { mList.setEmptyView(emptyView); } mList.setOnChildClickListener(this); mList.setOnGroupExpandListener(this); mList.setOnGroupCollapseListener(this); if (mFinishedStart) { setListAdapter(mAdapter); } mFinishedStart = true; }
@Override public void onLoadFinished( Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) { if (!isAdded()) return; final Intent includeApps = getArguments().getParcelable(EXTRA_INCLUDE_APPS); if (mAdapter == null) { mAdapter = new RootsExpandableAdapter(context, result, includeApps); Parcelable state = mList.onSaveInstanceState(); mList.setAdapter(mAdapter); mList.onRestoreInstanceState(state); } else { mAdapter.setData(result); } int groupCount = mAdapter.getGroupCount(); if(group_size != 0 && group_size == groupCount){ if (expandedIds != null) { restoreExpandedState(expandedIds); } } else { group_size = groupCount; for (int i = 0; i < group_size; i++) { mList.expandGroup(i); } expandedIds = getExpandedIds(); mList.setOnGroupExpandListener(mOnGroupExpandListener); mList.setOnGroupCollapseListener(mOnGroupCollapseListener); } }
expList.setOnGroupCollapseListener(new OnGroupCollapseListener()
exList.setAdapter(mAdapter); exList.setOnGroupCollapseListener(this); exList.setOnGroupExpandListener(this);