I am trying to update a database field, by Adapter. How do I do?

Asked

Viewed 28 times

0

...

public void concluirAtividade(Atividade atividade){

        ContentValues contentValues = new ContentValues();
        contentValues.put("SITUACAO", atividade.situacao);

        String[] parametros = new String[1];
        parametros[0] = String.valueOf(atividade.id);

        conexao.update("ATIVIDADES", contentValues, "ID = ?", parametros);
    }

....

public class ViewHolderAtividade extends RecyclerView.ViewHolder{

            public TextView txtAtividade;
            public TextView txtLocal;
            public TextView txtDataHora;
            public ImageButton imbExcluir;
            public ImageButton imbConcluir;
            public int requestCode = 0;
            public Atividade atividade;

            public ViewHolderAtividade (View itemView, final Context context){
                super(itemView);

                txtAtividade = (TextView)itemView.findViewById(R.id.txtAtividade);
                txtLocal = (TextView)itemView.findViewById(R.id.txtLocal);
                txtDataHora = (TextView)itemView.findViewById(R.id.txtDataHora);
                imbConcluir = (ImageButton)itemView.findViewById(R.id.imbConcluir);
                imbExcluir =(ImageButton)itemView.findViewById(R.id.imbExcluir);


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

                        if (dados.size()>0){
                            Atividade atividade = dados.get(getLayoutPosition());
                            Intent it = new Intent(context, InsereAtividade.class);
                            it.putExtra("ATIVIDADE",atividade);
                            ((AppCompatActivity)context).startActivityForResult(it, requestCode);
                        }
                    }
                });

                imbConcluir.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(dados != null && dados.size()>0){

                            atividade = dados.get(getLayoutPosition());
                            atividade.situacao = "Sim";atividadeRepositorio.concluirAtividade(atividade);
                            Toast.makeText(context,atividade.id, Toast.LENGTH_SHORT)
                                    .show();

                        }
                    }
                });

            }
        }

    }
  • 1

    Don’t ask a code-only question. Try to fully detail your problem by explaining which part of the code is in trouble and what specifically isn’t working

  • I have an Activity of activities with 3 fragments, two of them have recyclerview. I am using as database the Sqlite. I have in the table a situation field, that initially I carry it with "No" for activity not performed. I want to change this field to "Yes" when clicking a button on recyclerview. But when I call my method to complete activated launches a Nullpointerexception exception, what I do?

  • 1

    Post the Exception as well. It is as important or more important than the code itself.

  • Nullpointer Exception is being launched activityRepositorio.concluirActivity(activity);

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.