Problems adding ParseUser to an ArrayAdapter

0

I'm a beginner in java programming, I'm trying to get a specific ParseUser and send it to TimeLineFragment but it always gets null, I've done several tests, but it always gets null

public class TimeLineFragment extends Fragment {

    private ArrayList<ParseObject> feedTL;
    //private ArrayAdapter<ParseObject> adapter;
    private TimeLineLayout timeLineLayout;
    private ListView feedView;
    private ArrayList<ParseUser> userArray;
    private ParseUser user;



    public TimeLineFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_time_line, container, false);

        try {

            getPost();
            feedView = (ListView) view.findViewById(R.id.lista_post);
            feedTL = new ArrayList<>();
            //adapter = new TimeLineLayout(getActivity(), feedTL);
            timeLineLayout = new TimeLineLayout(getActivity(), feedTL);
            timeLineLayout.setImageUrl(user);
            feedView.setAdapter(timeLineLayout);

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




        return view;
    }

    public void getPost() {

        ParseQuery<ParseObject> query = new ParseQuery<>("shared");
        //query.whereNotEqualTo("userID", ParseUser.getCurrentUser().getObjectId());
        query.orderByDescending("createdAt");

        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> list, ParseException e) {
                if (e == null) {

                    if (list.size() > 0) {
                        feedTL.clear();
                        for (ParseObject parseObject : list) {

                            feedTL.add(parseObject);

                        }
                        timeLineLayout.notifyDataSetChanged();
                    }

                } else {
                    Toast.makeText(getActivity(), "Erro ao recuperar o feed", Toast.LENGTH_SHORT).show();
                }
            }
        });
        userArray = new ArrayList<>();
        ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
        userQuery.whereEqualTo("objectId", "WHVTz8ZiX2");
        userQuery.findInBackground(new FindCallback<ParseUser>() {
            @Override
            public void done(List<ParseUser> list, ParseException e) {
                if (e == null) {
                    if (list.size() > 0) {
                        for (ParseUser parseUser : list) {
                            userArray.add(parseUser);
                            user = userArray.get(0);
                            Log.i("user", " " + user.getParseFile("userPic").getUrl());
                        }
                    }else{
                        Log.i("Lista", "size = 0");
                    }
                }else{
                    Log.i("Erro", "Erro ao recuperar objeto");
                }
            }
        });
    }

TimeLineLayout.java

public class TimeLineLayout extends ArrayAdapter<ParseObject> {

    private Context context;
    private ArrayList<ParseObject> post;
    private ImageView picUsuario;
    private ParseUser imageUrl;



    public TimeLineLayout(Context c, ArrayList<ParseObject> objects) {
        super(c, 0, objects);
        this.context = c;
        this.post = objects;
    }

    public void setImageUrl(ParseUser imageUrl) {
        this.imageUrl = imageUrl;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (view == null){

            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.timeline_layout, parent, false);

        }

        TextView postTitle = (TextView) view.findViewById(R.id.tv_post_titulo);
        TextView postConteudo = (TextView) view.findViewById(R.id.tv_post_conteudo);
        picUsuario = (ImageView) view.findViewById(R.id.user_picture_post);

        ParseObject object = post.get(position);
        postTitle.setText(object.get("titulo").toString());
        postConteudo.setText(object.get("conteudo").toString());
        String userId = object.get("userID").toString();

        //-----------RECUPERAR USUÁRIOS-----------------

        if (imageUrl == null){
            Log.e("imageUrl: ", "null");
        }else{
            Log.e("imageUrl: ", "Not null");
        }

        return view;
    }

imageUrl is always null , I'm a beginner in programming

    
asked by anonymous 07.07.2018 / 03:22

0 answers