I have a ListView
that is composed of 3 ListView's
chained. The first is a Year Release list, which has a list of genres that in turn stores a list of movies. I wanted to have the option to expand and collapse the lists by the year and genre of the movies.
I already made Adapter's
to Swipe and I used this library:
link
From what I read, I need to have a label and expand the list from it, but in my case, the label is going to be an item from ListView
"parent".
I made a prototype of the screen to be easier to visualize:
TheSwipe
featurewillonlyexistinthemovielist.SomyMovieAdapterextendsBaseSwipeAdapter
,butsinceIwantittobeanExpandablelist,itwouldhavetoextendBaseExpandableListAdapter
.
AdapterFilme.java:
publicclassAdaptadorFilmeextendsBaseSwipeAdapter{String[]nomeFilmeint[]imgFilme;Contextcontext;privatestaticLayoutInflaterinflater=null;publicAdaptadorFilme(Contextcontext,int[]imgFilme,String[]nomeFilme){this.nomeFilme=nomeFilme;this.imgFilme=imgFilme;inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);}@OverridepublicintgetCount(){returnnomeFilme.length;}@OverridepublicObjectgetItem(intposition){returnposition;}@OverridepubliclonggetItemId(intposition){returnposition;}publicclassHolderextendsAppCompatActivity{ImageViewimgFilme;TextViewnomeFilme;SwipeLayoutswipeLayout;LinearLayoutlinearLayout;SwipeLayoutitem;}@OverridepublicintgetSwipeLayoutResourceId(intposition){returnR.id.swipeProd;}@OverridepublicViewgenerateView(finalintposition,ViewGroupparent){Viewv;finalHolderh;v=inflater.inflate(R.layout.lista_filmes,null);h=newHolder();h.imgFilme=(CheckBox)v.findViewById(R.id.img);h.nomeFilme=(ImageView)v.findViewById(R.id.nome);h.swipeLayout=(SwipeLayout)v.findViewById(getSwipeLayoutResourceId(position));h.imgFilme.setImageResource(imgFilme[position]);h.nomeFilme.setText(nomeFilme[position]);h.swipeLayout.addSwipeListener(newSwipeLayout.SwipeListener(){@OverridepublicvoidonStartOpen(SwipeLayoutlayout){}@OverridepublicvoidonOpen(SwipeLayoutlayout){}@OverridepublicvoidonStartClose(SwipeLayoutlayout){}@OverridepublicvoidonClose(SwipeLayoutlayout){}@OverridepublicvoidonUpdate(SwipeLayoutlayout,intleftOffset,inttopOffset){}@OverridepublicvoidonHandRelease(SwipeLayoutlayout,floatxvel,floatyvel){}});returnv;}@OverridepublicvoidfillValues(intposition,ViewconvertView){}
}
AdapterGenero.java
publicclassAdaptadorGeneroextendsBaseAdapter{finalHolderh=newHolder();String[]nomeFilme;int[]imgFilme;Contextcontext;AdaptadorFilmesadaptadorFilmesActivity;privatestaticLayoutInflaterinflater=null;publicAdaptadorGenero(inttipoAdap,String[]nomeFilme,String[]nomeGenero,String[]precosProdutos,int[]imgFilme,int[]qtd,Contextcontext){this.nomeFilme=nomeFilme;this.imgFilme=imgFilme;this.context=context;this.adaptadorFilmesActivity=newAdaptadorFilmes(context,imgFilme,nomeFilme);inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);}@OverridepublicintgetCount(){returnimgFilme.length;}@OverridepublicObjectgetItem(intposition){returnposition;}@OverridepubliclonggetItemId(intposition){returnposition;}publicclassHolder{TextViewnomeGenero;ImageViewsetinha;ListViewlistaFilmes;}@OverridepublicViewgetView(intposition,ViewconvertView,ViewGroupparent){Viewv;v=inflater.inflate(R.layout.lista_cat,null);h.nomeGenero=(TextView)v.findViewById(R.id.nomeitem);h.setinha=(ImageView)v.findViewById(R.id.setinha);h.nomeGenero.setText(nomeGenero[position]);h.listaFilmes.setAdapter(adaptadorFilmesActivity);calculeHeightListView();returnv;}privatevoidcalculeHeightListView(){inttotalHeight=0;ListAdapteradapter=h.listaFilmes.getAdapter();intlenght=adapter.getCount();for(inti=0;i<lenght;i++){ViewlistItem=adapter.getView(i,null,h.listaFilmes);listItem.measure(0,0);totalHeight+=listItem.getMeasuredHeight();}ViewGroup.LayoutParamsparams=h.listaFilmes.getLayoutParams();params.height=totalHeight+(h.listaFilmes.getDividerHeight()*(adapter.getCount()-1));h.listaFilmes.setLayoutParams(params);h.listaFilmes.requestLayout();}
}
TheYearAdapterfollowsthesameideaastheGenderAdapter.HowdoIclickonthelittleboxofListView
"parent" to ListView
"child" to be displayed / hidden?