为什么显示空数据?

时间:2018-10-26 08:03:27

标签: android android-recyclerview retrofit2

我正在开发简历应用程序,但显示白屏,我已经在Postman中检查了json响应,但显示了。

我的LogCat下方

D/Surface: Surface::connect(this=0xa232a700,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
I/System.out: [socket][0] connection www.mocky.io/52.210.139.55:80;LocalPort=-1(10000)
D/: [Posix_connect Debug]Process activity.drawer.navigation.com.kitabsawticlone :80 
E/RecyclerView: No adapter attached; skipping layout

我的JSON链接下面

  

http://www.mocky.io/v2/5bd2bce93400000f00cfde57

在我进行改造调用的IntroductionItem.java下面

public class IntroductionItem extends AppCompatActivity {

  public List<Introduction> introductionList;
  public IntroductionAdapter adapter;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.introduction);
        KitabInterface kitabInterface = ApiClient.getApiService();
        Call<KitabSawti> call = kitabInterface.getIntroduction();

        call.enqueue(new Callback<KitabSawti>() {
            @Override
            public void onResponse(Call<KitabSawti> call, Response<KitabSawti> response) {
            introductionList =  response.body().getIntroduction();
            RecyclerView recyclerView  =  findViewById(R.id.recyclerView);
            adapter = new IntroductionAdapter(introductionList);
                recyclerView.setHasFixedSize(true);
                recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
                recyclerView.setAdapter(adapter);



            }

            @Override
            public void onFailure(Call<KitabSawti> call, Throwable t) {

            }
        });



    }
}

在我的api客户端类下面

public class ApiClient

{


        public static final String BASE_URL = "http://www.mocky.io/";

        /**
         * Get Retrofit Instance
         */


        public static Retrofit getRetrofitInstance() {
            return new Retrofit.Builder()

                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();

        }

        /**
         * Get API Service
         *
         * @return API Service
         */
        public static KitabInterface getApiService() {
            return getRetrofitInstance().create(KitabInterface.class);
        }
    }

在我放置终点的接口类下面

public interface KitabInterface {

    @GET("/v2/5bd2bce93400000f00cfde57")
    Call<KitabSawti> getIntroduction();



}

在我的适配器下面

public class IntroductionAdapter extends RecyclerView.Adapter<IntroductionAdapter.MyViewHolder> {


    private List<Introduction> moviesList;

    public IntroductionAdapter(List<Introduction> moviesList) {
        this.moviesList = moviesList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.introduction_list, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
        final Introduction introduction = moviesList.get(position);

        if (introduction.getImage() != null) {

            Picasso.get().load(introduction.getImage()).
                    networkPolicy(NetworkPolicy.OFFLINE).transform(new RoundedCornersTransformation()).into(holder.imageView, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError(Exception e) {
                    Picasso.get().load(R.drawable.ic_contact).
                            into(holder.imageView);
                }
            });

        }
        holder.introduction.setText(introduction.getIntroduction());

    }

    @Override
    public int getItemCount() {
        return moviesList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView introduction, about;
        public ImageView imageView;

        public MyViewHolder(View view) {
            super(view);

            imageView = (ImageView) view.findViewById(R.id.imageView);
            introduction = (TextView) view.findViewById(R.id.introduction);
            about = (TextView) view.findViewById(R.id.about);


        }
    }
}

0 个答案:

没有答案