listview adapter repeats the values saved in id

0

I'm trying to bring up the values from the database and load into a listview, I already swipe from the database an object with the data (a list of "modules"), and tried to pass the id of the corresponding row in the bank via Intent for the other activity to load the values corresponding to the id that was passed, the problem is that the adapter loads the data of the bank putting each item right in the listView, but the id it only passes to another activity like intent with the value 1, indepentente of which is the true id.

follow the code snippet:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_adapter,null);
        holder = new ViewHolder();
        holder.tituloView = (TextView)convertView.findViewById(R.id.titulo2);
        holder.progressBar =
(ProgressBar)convertView.findViewById(R.id.progress);
        holder.button = (Button)convertView.findViewById(R.id.buttonModulo);

    }else{
        holder = (ViewHolder)convertView.getTag();
    }

    modulos = new Modulos();
    modulos = modulosList.get(position);

    Log.i("idModulo:"," "+modulos.getId());
    String titulo = modulos.getTitulo();
    holder.tituloView.setText(titulo);

    baixarImagem(convertView,modulos,context,holder);

    holder.progressBar.setMax(8);



    holder.progressBar.setProgress(4);

    holder.button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Bundle bundle = new Bundle();
            bundle.putString("id",modulos.getId());
            Intent intent = new Intent(context, ListaAulasActivity.class);
            intent.putExtras(bundle);
            intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
            Log.i("idModuloEnviado: ",""+modulos.getId());
            context.startActivity(intent);
        }
    });

    convertView.setTag(holder);
    return convertView;
}
    
asked by anonymous 25.07.2017 / 02:57

1 answer

1

To call the attributes of each item in the list, use OnItemClickListener in the ListView.

seuListView.setOnItemClickListener(onCliqueItemLista());

Event:

private AdapterView.OnItemClickListener onCliqueItemLista() {
    return new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            idModulo = modulosList.get(position).getId();
            Bundle bundle = new Bundle();
            bundle.putString("id",modulos.getId());
            Intent intent = new Intent(context, ListaAulasActivity.class);
            intent.putExtras(bundle);
            intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
            Log.i("idModuloEnviado: ",""+modulos.getId());
            context.startActivity(intent);
        }
    };
}
    
25.07.2017 / 16:16