Button does not call web service method

Asked

Viewed 40 times

3

I’m having trouble calling a method from my webservice,this method I send the boleto by email to the user, for some reason it’s not working. I have a listview with all the boletos and the user selects which one he wants to see the details and in this Activity of details I have 3 functions that is to send the boleto by email, send type line of the boleto by sms or just show the line.

This is the onClick method I have in Activity of details. is missing something? for even the logs they show me.

 @Override
    public void onClick(View v) {
       switch (v.getId()){

           case R.id.enviaBoletoEmail:
               Log.d("","ENVIANDO BOLETO test 1");

               new Thread(new Runnable() {
                      @Override
                      public void run() {
                          WebService ws = new WebService();
                          Log.d("","ENVIANDO BOLETO teste 2");
                          try {
                              pessoaDao = new PessoaDao(databaseHelper.getConnectionSource());
                              Pessoa pessoa=new Pessoa();
                              pessoa= pessoaDao.queryForId(1);

                              try {
                                  ws.enviarBoletoPDF(sequencia, pessoa.getEmail());

                                  Log.d("","ENVIANDO BOLETO test 3");

                              } catch (IOException e) {
                                  e.printStackTrace();
                              } catch (XmlPullParserException e) {
                                  e.printStackTrace();
                              }


                          } catch (SQLException e) {
                              e.printStackTrace();
                          }




                      }
                  }).start();

            break;

1 answer

0


I was able to solve the issue, researching more what could be causing my problem, I found about good practices on how to use click events.

It was as follows:

public View.OnClickListener btnEnviaBoletoPDF = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
             WebService ws = new WebService();

            try {

                pessoaDao = new PessoaDao(databaseHelper.getConnectionSource());
                Pessoa pessoa = new Pessoa();
                pessoa = pessoaDao.queryForId(1);
                Log.d("Sequencia", sequencia);
                ws.enviarBoletoPDF(sequencia,pessoa.getEmail());

            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }
    };

in the onCreate method:

enviaBoletoEmail = (Button) findViewById(R.id.enviaBoletoEmail);
enviaBoletoEmail.setOnClickListener(btnEnviaBoletoPDF);

Browser other questions tagged

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