Функция функции getView в классе адаптера работает с бесконечным l oop после выборки профилей с сервера? - PullRequest
0 голосов
/ 24 марта 2020

Код моего адаптера

public class profiles_adapter extends ArrayAdapter<profiles> {
Context context;

public profiles_adapter(Context context, int resourceId, List<profiles> items) {
    super(context, resourceId, items);
    this.context = context;
}

public View getView(int position, View convertView, @NotNull ViewGroup parent) {


    profiles profile = getItem(position);

    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.cards, parent, false);

    }

    TextView card_name = convertView.findViewById(R.id.card_name);
    card_name.setText(profile.getPet_name());
    TextView card_age = convertView.findViewById(R.id.card_age);
    card_age.setText(String.valueOf(profile.getAge()));
    TextView college_name = convertView.findViewById(R.id.college_name);
    college_name.setText(profile.getCollege());

return convertView;
   }

Мой класс, который устанавливает адаптер

    profiles_adapter = new profiles_adapter(getContext(), R.layout.cards, profile_list);
    SwipeFlingAdapterView flingContainer = view.findViewById(R.id.swipe_layout);
    flingContainer.setAdapter(profiles_adapter);

код, в котором я устанавливаю профили и уведомляю адаптер об изменении

getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {

                                for (int j = 0; j < profiles.length(); j++) {
                                    JSONObject object = null;
                                    try {
                                        object = (JSONObject) profiles.get(j);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    //add a model
                                    profiles model = new Gson().fromJson(String.valueOf(object), profiles.class);
                                    profile_list.add(model);
                                }
                                profiles_adapter.notifyDataSetChanged();
                                progressHUD.dismiss();
                            }

                        });

Это потому, что я уведомляю адаптер внутри метода runOnUI, может ли кто-нибудь мне помочь, я застрял на этом

...