在改造响应中调用方法

时间:2019-04-22 14:41:27

标签: android mongodb retrofit retrofit2

我的api中有两个方法,我必须分别调用它们,因为每个方法都返回一个不同的对象,实际上,当我对其进行测试时,它可以正常工作,但问题是,当我不得不对其进行第二次测试时,它会出现bug。并且我想确保我的代码正确与否。

   IFiche IFiche = APIClient.getClient().create(IFiche.class);

                        String ItemsSP = GetItemSelectedSP();
                        String ItemsAntc = GetItemSelectedAntc();

                        IFiche.add(Double.parseDouble(age.getText().toString()), Double.parseDouble(EVA.getText().toString())
                                , ItemsSP, ItemsAntc, motif.getText().toString(), total_score,Integer.parseInt(ID))
                                .enqueue(new Callback<FichePatient>() {
                                    @Override
                                    public void onResponse(Call<FichePatient> call, Response<FichePatient> response) {
                                        Toast.makeText(getApplicationContext(), "Succees", Toast.LENGTH_LONG).show();
                                        IUser IUser = APIClient.getClient().create(IUser.class);
                                        IUser.affecterliste_fiche(Integer.parseInt(ID), Integer.parseInt(response.body().getId()),
                                                total_score).enqueue(new Callback<Users>() {
                                            @Override
                                            public void onResponse(Call<Users> call, Response<Users> response) {
                                                Toast.makeText(getApplicationContext(), "HIIIIII", Toast.LENGTH_LONG).show();
                                                response.body().setLastScore(total_score);
                                                Intent intent= new Intent(getApplicationContext(),NavigationActivity.class);
                                                startActivity(intent);
                                            }

                                            @Override
                                            public void onFailure(Call<Users> call, Throwable t)
                                            {
                                                Toast.makeText(getApplicationContext(), "NOOO", Toast.LENGTH_LONG).show();
                                                Log.v("TAG!!!!!!!!!!", "error   " + t.getMessage());
                                            }
                                        });
                                    }

                                    @Override
                                    public void onFailure(Call<FichePatient> call, Throwable t) {
                                        Log.v("TAG!!!!!!!!!!!", "error   " + t.getMessage());
                                        Toast.makeText(getApplicationContext(), "erreur", Toast.LENGTH_LONG).show();
                                    }
                                });

0 个答案:

没有答案