I do a parser for VK. On the wall, everything is displayed, except for pictures! Do not understand why!

if(!VKSdk.isLoggedIn()) { loginVK.setVisibility(View.VISIBLE); }else{ VKRequest reqWall=VKApi.wall().get(VKParameters.from("owner_id", owner_id, VKSdk.getAccessToken().userId, VKApiConst.EXTENDED, 1, VKApiConst.COUNT,200 ,VKApiConst.FIELDS, "text")); reqWall.setPreferredLang("ru"); reqWall.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); JSONObject jsonObject = response.json; String owner = null; try { owner = (((JSONObject) ((JSONArray) ((JSONObject) jsonObject.get("response")).get("items")).get(0)).getString("owner_id")); } catch (JSONException e) { e.printStackTrace(); } VKPostArray posts = new VKPostArray(); try { posts.parse(response.json); } catch (JSONException e) { e.printStackTrace(); } try { JSONArray array = ((JSONArray) ((JSONObject) jsonObject.get("response")).get("groups")); } catch (JSONException e) { e.printStackTrace(); } VKApiPost p = posts.get(0); VKAttachments at = p.attachments; VKAttachments.VKApiAttachment test = at.get(0); imageLoader.getInstance(); try { Log.v("test", (((JSONObject) ((JSONArray) ((JSONObject) jsonObject.get("response")).get("profiles")).get(0)).getString("id"))); } catch (JSONException e) { e.printStackTrace(); } RecyclerView rv = (RecyclerView) findViewById(R.id.userWall); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext()); rv.setLayoutManager(linearLayoutManager); RecyclerAdapterWall adapterWall = new RecyclerAdapterWall(getApplicationContext(), posts); rv.setAdapter(adapterWall); 

 public class RecyclerAdapterWall extends RecyclerView.Adapter<RecyclerAdapterWall.ViewHolder>{ Context ctx; ImageLoader imageLoader; String owner_id; VKPostArray obj; public RecyclerAdapterWall(Context ctx, VKPostArray posts) { //super(ctx,R.layout.recycler_item_wall); this.obj= posts; this.ctx= ctx; imageLoader.getInstance(); } public RecyclerAdapterWall(Context ctx, VKPostArray posts, String owner_id) { //super(ctx,R.layout.recycler_item_wall); this.obj= posts; this.ctx= ctx; this.owner_id= owner_id; imageLoader.getInstance(); } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_wall,parent,false); ViewHolder viewHolder= new ViewHolder(v); return viewHolder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { final VKApiPost p= obj.get(position); holder.imageWall.setVisibility(View.VISIBLE); holder.textPost.setText(p.text); java.util.Date time= new java.util.Date((long)p.date*1000); holder.textDatePost.setText(String.valueOf(time)); //new GetUsersTask(holder.textNamePost,holder.imageWall,ctx).execute(String.valueOf(p.from_id)); new GetUsersTask(holder.textNamePost, holder.imageWall, ctx, imageLoader).execute(String.valueOf(p.from_id)); } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); } @Override public int getItemCount() { return obj.size(); } public static class ViewHolder extends RecyclerView.ViewHolder{ CardView cv; TextView textNamePost; TextView textDatePost; TextView textPost; ImageView imageWall; public ViewHolder(View itemView) { super(itemView); cv=(CardView) itemView.findViewById(R.id.card_view_wall); textDatePost=(TextView)itemView.findViewById(R.id.textDatePost); //textNamePost=(TextView)itemView.findViewById(R.id.textNamePost); textPost=(TextView)itemView.findViewById(R.id.textPost); imageWall=(ImageView)itemView.findViewById(R.id.imageWall); } } } 

================================================

 public class GetUsersTask extends AsyncTask<String, Void, VKApiUser> { TextView textView; ImageView imageView; ImageLoader imageLoader; Context context; VKApiUser vkApiUser; public GetUsersTask(TextView textView,ImageView imageView,Context context,ImageLoader imageLoader) { this.textView=textView; this.imageView=imageView; this.context=context; this.imageLoader=ImageLoader.getInstance(); } protected VKApiUser doInBackground(String... id) { String ID = id[0]; final VKApiUser[] user1 = new VKApiUser[1]; VKRequest request= VKApi.users().get(VKParameters.from(VKApiConst.USER_ID, ID,VKApiConst.FIELDS,"photo_100")); request.setPreferredLang("ru"); request.executeSyncWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); VKList<VKApiUser> us = ((VKList<VKApiUser>) response.parsedModel); user1[0] = us.get(0); } }); return user1[0]; } protected void onPostExecute(VKApiUser result) { if(result!=null) { textView.setText(result.first_name + " " + result.last_name); /*imageLoader.init(ImageLoaderConfiguration.createDefault(context)); DisplayImageOptions options=new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) .build(); */ imageLoader.displayImage(result.photo_100, imageView); Picasso.with(context).setIndicatorsEnabled(true); Picasso.with(context) .load(result.photo_100) .into(imageView); } } 
  • Well ? where is the code itself? Everything in GetUsersTask is done and you don’t show it to us? - Shwarz Andrei

1 answer 1

Try using the Retrofit 2 library to load json data and pars.

here is an example of using http://guides.codepath.com/android/Consuming-APIs-with-Retrofit

and for downloading pictures you can try Picasso: http://square.imtqy.com/picasso/

  • Please try to publish detailed answers containing a specific example of the minimum solution, supplementing them with a link to the source. Answers –references (as well as comments) do not add knowledge to the Runet. - Nicolas Chabanovsky
  • yes yes yes do not add knowledge to ru No, an intelligent person should orient himself on how to use, but he only needs to show what to use. - KolinLoures