首页 > 解决方案 > Android改造后数据

问题描述

我正在使用带有 Retrofit 的 Android Recyclerview,它在没有任何发布数据的情况下工作。我需要在我当前的代码中发布一些数据。

下面是我当前的 ApiInterface

public interface ApiInterface {
   @GET("mypage.php")
   Call<Pojo> getData();
}

在我的活动中,我通过以下代码调用它

ApiInterface apiInterface = (ApiInterface) RetrofitClient.getRetrofitInstance().create(ApiInterface.class);
    Call<Pojo> listingdata = apiInterface.getData();
    listingdata.enqueue(new Callback<Pojo>() {
        @Override
        public void onResponse(Call<Pojo> call, Response<Pojo> response) {

            if(response.isSuccessful()){
                recycleradpter recycleradpter = new recycleradpter(response.body().getData());
                recyclerView.setAdapter(recycleradpter);
                progressbar2.setVisibility(View.GONE);
            }

        }

        @Override
        public void onFailure(Call<Pojo> call, Throwable t) {
            //System.out.println("12345678934567890234567890");
            //Toast.makeText(getActivity(), "No Connected internet", Toast.LENGTH_SHORT).show();
           progressbar2.setVisibility(View.GONE);
            dialogfunction();
        }
    });

如何根据上述代码中传递的数据获取数据

标签: androidretrofit2

解决方案


如果要发送发布请求,则必须创建如下所示的方法。该方法的调用将类似于获取请求。只需传递您的帖子正文的参数。你可以在这里了解详情。

 @POST("mypage.php")
 Call<Pojo> postData(
     @Field("param1") String param1,
     @Field("param2") int param2
 );

推荐阅读