适配器未解析我发送给它的数组列表

问题描述 投票:0回答:1

我正在使用此滑动库https://github.com/Diolor/Swipecards

这里是我从中获取数据并将其存储在ArrayList中的代码(数据正确地来自服务器)

JSONObject json = new JSONObject(mMessage);
                    JSONArray profiles = json.getJSONArray("profiles");

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

这些是适配器和Arraylist的声明

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

这是我的适配器代码

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


public profiles_adapter(Context context, int resourceId, ArrayList<profiles> item) {
    super(context, resourceId, item);
    this.context=context;
}
  Public View getView(int position, View convertView, ViewGroup parent) {

   final profiles profile = getItem(position);


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

    TextView card_name = (TextView) convertView.findViewById(R.id.card_name);
    card_name.setText(profile.getPet_name());
    TextView card_age = (TextView) convertView.findViewById(R.id.card_age);
    card_age.setText(profile.getAge());
}
android android-recyclerview adapter
1个回答
0
投票

下面的代码有一些更改,

© www.soinside.com 2019 - 2024. All rights reserved.