6
I have a ListView
which is composed of 3 ListView's
chained. The first is a list of Year of release, which has a list of genres that in turn stores a list of movies. I wanted to have the option to expand and contract lists by year and genre of films.
I’ve already done the Adapter's
for Swipe and I used this library:
https://github.com/daimajia/AndroidSwipeLayout
From what I read, I need to have a label and expand the list from it, but in my case, the label will be an item from ListView
"father".
I made a prototype of the screen to make it easier to visualize:
The functionality of Swipe
will exist only in the movie list. Then my Adapter der movies extends BaseSwipeAdapter
, only since I want it to be an expandable list, I’d have to extend it BaseExpandableListAdapter
.
Java adapter.:
public class AdaptadorFilme extends BaseSwipeAdapter {
String [] nomeFilme
int [] imgFilme;
Context context;
private static LayoutInflater inflater = null;
public AdaptadorFilme(Context context, int[] imgFilme,String[] nomeFilme) {
this.nomeFilme = nomeFilme;
this.imgFilme = imgFilme;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return nomeFilme.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class Holder extends AppCompatActivity {
ImageView imgFilme;
TextView nomeFilme;
SwipeLayout swipeLayout;
LinearLayout linearLayout;
SwipeLayout item;
}
@Override
public int getSwipeLayoutResourceId(int position) {
return R.id.swipeProd;
}
@Override
public View generateView(final int position, ViewGroup parent) {
View v;
final Holder h;
v = inflater.inflate(R.layout.lista_filmes, null);
h = new Holder();
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(new SwipeLayout.SwipeListener() {
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onClose(SwipeLayout layout) {
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
}
});
return v;
}
@Override
public void fillValues(int position, View convertView) {
}
}
Java adapter.
public class AdaptadorGenero extends BaseAdapter {
final Holder h = new Holder();
String[] nomeFilme;
int []imgFilme;
Context context;
AdaptadorFilmes adaptadorFilmesActivity;
private static LayoutInflater inflater = null;
public AdaptadorGenero(int tipoAdap,String[] nomeFilme, String[] nomeGenero, String[] precosProdutos, int[] imgFilme, int[] qtd, Context context) {
this.nomeFilme = nomeFilme;
this.imgFilme = imgFilme;
this.context = context;
this.adaptadorFilmesActivity = new AdaptadorFilmes(context,imgFilme,nomeFilme);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return imgFilme.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class Holder{
TextView nomeGenero;
ImageView setinha;
ListView listaFilmes;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
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();
return v;
}
private void calculeHeightListView() {
int totalHeight = 0;
ListAdapter adapter = h.listaFilmes.getAdapter();
int lenght = adapter.getCount();
for (int i = 0; i < lenght; i++) {
View listItem = adapter.getView(i, null, h.listaFilmes);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = h.listaFilmes.getLayoutParams();
params.height = totalHeight
+ (h.listaFilmes.getDividerHeight() * (adapter.getCount() - 1));
h.listaFilmes.setLayoutParams(params);
h.listaFilmes.requestLayout();
}
}
The Year adapter follows the same idea of gender.
How do I click on the arrow ListView
"father" to ListView
"child" is displayed/hidden?