private void initListView() { this.mStarAdapter = new StarAdapter(this, this.mStarName); this.mStarAdapter.setStarBookCallback(this.mBooedkProgramsCallback); this.mListView.setAdapter(this.mStarAdapter); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels; this.mListView.setHeaderLayoutParams(new LayoutParams(screenWidth, (int) (9.0f * (((float) screenWidth) / 16.0f)))); this.mListView.setScrollViewCallbacks(this); ((ExpandableListView) this.mListView.getRootView()).setGroupIndicator(null); ((ExpandableListView) this.mListView.getRootView()).setOnGroupClickListener(new OnGroupClickListener(this) { final /* synthetic */ StarActivity this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) { return true; } }); }
/** * 初始化可拓展列表 */ private void initExpandListView() { statusAdapter = new ExpandLvAdapter(context, getListData()); expandlistView.setAdapter(statusAdapter); expandlistView.setGroupIndicator(null); // 去掉默认带的箭头 expandlistView.setSelection(0);// 设置默认选中项 // 遍历所有group,将所有项设置成默认展开 final int groupCount = expandlistView.getCount(); for (int i = 0; i < groupCount; i++) { expandlistView.expandGroup(i); } expandlistView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if(parent.isGroupExpanded(groupPosition)) { parent.collapseGroup(groupPosition); } else { parent.expandGroup(groupPosition); } return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); elv = (ExpandableListView) findViewById(R.id.lvExp1); elv.setFocusable(false); /** * THIS CAN BE USED IN ACTIVITY OR FRAGMENTS * **/ elv.setAdapter(new CustomELVAdapter(this, MainActivity.this, groupname, ImgBckgrnd, listinfo,data)); elv.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { /** * TODO:return true to enable group click */ // DO SOMETHING return false; } }); }
/** * @see ExpandableListView#setOnGroupClickListener(OnGroupClickListener) */ public W setOnGroupClickListener(OnGroupClickListener onGroupClickListener) { mView.setOnGroupClickListener(onGroupClickListener); return (W) this; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_library, container, false); list = (ExpandableListView) view.findViewById(R.id.list); list.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (list.isGroupExpanded(groupPosition)) { return false; } else { if (artists == null) return true; LibraryArtist artist = artists.get(groupPosition); if (artist == null) return true; if (artist.getAlbums() == null) { try { artist.initAlbums(app.oMPDAsyncHelper.oMPD.getAlbums(artist, true)); } catch (MPDServerException e) { artist.initAlbums(null); e.printStackTrace(); } } if (albumToDisplay != null) { privateDisplayAlbum(albumToDisplay, artist, groupPosition); albumToDisplay = null; } return false; } } }); loadingView = view.findViewById(R.id.loadingLayout); loadingTextView = (TextView) view.findViewById(R.id.loadingText); loadingTextView.setText(R.string.library_loading_artists); noResultView = view.findViewById(R.id.noResultLayout); pullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.pullToRefresh); lastPosition = -1; if (savedInstanceState != null) { lastPosition = savedInstanceState.getInt(EXTRA_POSITION, 0); } return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<GroupItem> items = new ArrayList<GroupItem>(); // Populate our list with groups and it's children for(int i = 1; i < 100; i++) { GroupItem item = new GroupItem(); item.title = "Group " + i; for(int j = 0; j < i; j++) { ChildItem child = new ChildItem(); child.title = "Awesome item " + j; child.hint = "Too awesome"; item.items.add(child); } items.add(item); } adapter = new ExampleAdapter(this); adapter.setData(items); listView = (AnimatedExpandableListView) findViewById(R.id.listView); listView.setAdapter(adapter); // In order to show animations, we need to use a custom click handler // for our ExpandableListView. listView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { // We call collapseGroupWithAnimation(int) and // expandGroupWithAnimation(int) to animate group // expansion/collapse. if (listView.isGroupExpanded(groupPosition)) { listView.collapseGroupWithAnimation(groupPosition); } else { listView.expandGroupWithAnimation(groupPosition); } return true; } }); }