When the person clicks on item A in the categoria
fragment I would need to take to an activity. And when I click on item B to take to another activity, so I can make the filters.
Here the class of the items:
public class Itens {
private int imagem;
public Itens(int imagem) {
this.imagem = imagem;
}
public int getImagem() {
return imagem;
}
public void setImagem(int imagem) {
this.imagem = imagem;
}
}
Here the adapter:
public class CategoriaAdapter extends ArrayAdapter<Itens> {
private Context context;
private ArrayList<Itens> lista;
public CategoriaAdapter(Context context, ArrayList<Itens> lista) {
super(context,0,lista);
this.context = context;
this.lista = lista;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Itens itemPosicao = this.lista.get(position);
convertView = LayoutInflater.from(this.context).inflate(R.layout.lista_categoria,null);
ImageView imageView = (ImageView) convertView.findViewById(R.id.image_lista_categoria);
imageView.setImageResource(itemPosicao.getImagem());
return convertView;
}
}
And here's the snippet:
public class PorCategoria extends Fragment {
private ArrayAdapter<Itens> adapter;
public PorCategoria() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_por_categoria, container, false);
final ArrayList<Itens> lista = new ArrayList<Itens>();
Itens a = new Itens(R.drawable.categoria1);
Itens b = new Itens(R.drawable.categoria2);
Itens c = new Itens(R.drawable.categoria3);
Itens d = new Itens(R.drawable.categoria4);
Itens e = new Itens(R.drawable.categoria5);
lista.add(a);
lista.add(b);
lista.add(c);
lista.add(d);
lista.add(e);
adapter = new CategoriaAdapter(getActivity(),lista);
ListView listaCategoria = (ListView) view.findViewById(R.id.list_categoria);
listaCategoria.setAdapter(adapter);
return view;
}
}