expandablelistview - How to implement Expandable items with LinearLayoutManager (introduced with Android L) -
recycler view
is presented with Android L and is part of the AppCompat v7 library. Then I decided to update my app with this brand to replace the new recycler
to replace my ListView
s, layout manager to
recycler view
, I am using LinearLayoutManager
, which works fine.
There are hard things: when I want to change my ExpandableListView
to a RecyclerView
. Since Google has not created " expandable layout manager"
, it is very difficult and I can not get it.
It mentions the children, but it appears as children of the original scene See Recycling
not children themselves.
Does anyone have an alternative solution or some clue about it? Or at least such a notification should start from where I can apply my own layout manager
.
This helps you to group items in your "items" After that you can apply extension / collapse functionality in it.
First you create your section Category:
Class MySection Expands StatelessSection {String Header; & Lt; String & gt; List; Boolean extension = true; Public Micection (String Header, List & lt; String & gt; List) {Call Constructor with Layout Resources for this column header and item Super (R.Lite.action_header, R.Lite.action_item); This.myHeader = Header; This.myList = List; } @ Override public int getContentItemsTotal () {extended extended? List.size (): 0; } @ Override Public Recycler View SeeHolder HathawayVihilder (see view) {see new headerviller (see); } @ Override Public Wide On BidderWiller (Recyclable Viv. Viewholder Holder) {The Ultimate HeaderViewholder HeaderHolder = (HeaderviewHolder) Holder; HeaderHolder.tvTitle.setText (title); HeaderHolderkrootViewksetOnClickListener (new View.OnClickListener () {@Override on public void (see V) {Extended! = Has expanded; headerHolder.imgArrow.setImageResource (Extended? R.drawable.ic_keyboard_arrow_up_black_18dp: R.drawable .ic_keyboard_arrow_down_black_18dp); section adapter .notifyDataSetChanged ();}}); } @ Override Public Recyclable Weave Wihiholder getItemViewHolder (see view) {// Returning a custom example of ViewHolder for the items of this section, the new MyItemViewHolder (see); } @ Override BindItemViewHolder (public viewer, viewer holder, int status) on public Zero {MyItemViewHolder itemHolder = (MyItemViewHolder) Holder; // Tie your view here item.Holder.tvItem.setText (list.get (position)); }}
Then create instances of your sections and set up your adapter:
Create an instance of // SectionedRecyclerViewAdapter section RecyclerViewAdapter Anubagadetr = new section RecyclerViewAdapter (); // your section section Jodenadaptr.adsakshn (new Maissekshn ( "Section 1", Arejh.aselaiais (new String [] { "Item 1", "Item 2", "Item 3", "Item 4"}))); SectionAdapter.addSection (new MySection ( "Section 2", Arrays.asList (new String [] { "Item 1", "Item 2"}))); // set with SectionedRecyclerViewAdapter recycle your RecyclerView to RecyclerView = (Punrchyrdrishy) searches ViewById (R.id.recyclerview); RecyclerView.setLayoutManager (new LinearLayoutManager (getContext ())); RecyclerView.setAdapter (sectionAdapter);
Comments
Post a Comment