Does anyone know how to pull an ID of a ListView item through SetOnItemLongClickListener
and could you tell me if this method would work with an item being displayed from the database ??
The Adapter code:
public class ObjetoAdapter extends BaseAdapter {
private List<Objeto> objeto;
private Context context;
public ObjetoAdapter(Context context, List<Objeto> objeto) {
this.objeto = objeto;
this.context = context;
}
@Override
public int getCount() {
return objeto.size();
}
@Override
public Object getItem(int arg0) {
return objeto.get(arg0);
}
@Override
public long getItemId(int position) {
return objeto.get(position).getId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rootView = LayoutInflater.from(context).inflate(R.layout.lista_objetos, parent, false);
TextView tvID = (TextView) rootView.findViewById(R.id.tvID);
TextView tvNome = (TextView) rootView.findViewById(R.id.tvLvNome);
TextView tvValor = (TextView) rootView.findViewById(R.id.tvLvValor);
Objeto objetoDaVez = objeto.get(position);
tvID.setText("ID: " + getItemId(position));
tvNome.setText(" Nome" + objetoDaVez.getNome());
tvValor.setText(" Valor: R$" + objetoDaVez.getValor());
return rootView;
}