0
The Toast of the onListItemClick method never appears, someone knows what I did wrong?
Code:
public class TiposFragment extends ListFragment {
private ArrayList<Tipo> tipos;
private TipoAdapter tipoAdapter;
private int selecionado;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
try {
Bundle bundle = getArguments();
if (bundle != null) {
tipos = bundle.getParcelableArrayList("tipos");
}
} catch (Exception e) {
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_LONG).show();
}
if (tipos != null) {
try {
tipoAdapter = new TipoAdapter(getContext(), tipos);
setListAdapter(tipoAdapter);
ListView listaTipos = getListView();
listaTipos.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Toast.makeText(getContext(),String.valueOf(listaTipos.getCount()),Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
super.onListItemClick(lv, v, position, id);
selecionado = tipoAdapter.getItem(position).tipCod;
Toast.makeText(getContext(), String.valueOf(selecionado), Toast.LENGTH_SHORT).show();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tipo_trilha, container, false);
return view;
}
It didn’t work out, but I’ve never seen set the system for onListItemClick
– Danilo Nadolny Vizentainer
a question, Voce even need to instantiate un Listfragment, or it can be any other type?
– Armando Marques Sobrinho
It may be any type I think, but it has to be Fragment
– Danilo Nadolny Vizentainer
then a guy, mounts your Adapter and passes it to a normal listview directly in a Fragment, besides being easier to implement, Oce has more control over the components. I’m running here now, but if you wait I’ll put another answer with an example, it might be?
– Armando Marques Sobrinho