Android 适配器没有解析我发送给它的arraylist

Android 适配器没有解析我发送给它的arraylist,android,android-recyclerview,adapter,Android,Android Recyclerview,Adapter,我正在使用这个刷库 下面是我获取数据并存储在ArrayList中的代码(数据正确地来自服务器) 这是我的适配器代码 public class profiles_adapter extends ArrayAdapter<profiles> { Context context; public profiles_adapter(Context context, int resourceId, ArrayList<profiles> item) { super(co

我正在使用这个刷库

下面是我获取数据并存储在ArrayList中的代码(数据正确地来自服务器)

这是我的适配器代码

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());
}
公共类配置文件\u适配器扩展了ArrayAdapter{
语境;
公共配置文件\u适配器(上下文上下文、int resourceId、ArrayList项){
超级(上下文、资源ID、项目);
this.context=context;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
最终外形外形=获取项目(位置);
if(convertView==null){
convertView=LayoutInflater.from(getContext()).flate(R.layout.cards,父项,false);
}
TextView卡_名称=(TextView)convertView.findViewById(R.id.card_名称);
card_name.setText(profile.getPet_name());
TextView card_age=(TextView)convertView.findViewById(R.id.card_age);
card_age.setText(profile.getAge());
}

您的代码中有一些更改,如下所示:

                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();
jsonobjectjson=newjsonobject(mMessage);
JSONArray profiles=json.getJSONArray(“profiles”);
对于(int j=0;j
适配器文件将是

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

 public profiles_adapter(Context context, int resourceId, ArrayList<profiles> 
 item) {

this.context=context;
this.profileArraylist = item;
 }
Public View getView(int position, View convertView, ViewGroup parent) {

final profiles profile = profileArraylist.get(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());
 }
公共类配置文件\u适配器扩展了ArrayAdapter{
语境;
Arraylist Profile Arraylist;
公共配置文件\u适配器(上下文上下文、int-resourceId、ArrayList
(项目){
this.context=context;
this.profileArraylist=项目;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
最终配置文件profile=profileArraylist.get(位置);
if(convertView==null){
convertView=LayoutInflater.from(getContext()).flate(R.layout.cards,父项,false);
}
TextView卡_名称=(TextView)convertView.findViewById(R.id.card_名称);
card_name.setText(profile.getPet_name());
TextView card_age=(TextView)convertView.findViewById(R.id.card_age);
card_age.setText(profile.getAge());
}

试试这个,它会帮你找出问题。

不,它不工作,但调试器说:profiles.getView(),挂起的线程OK让我检查一下我应该发布卡布局和刷卡布局的xml吗?是的,你也可以发布上面错误的日志文件吗
                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();
  public class profiles_adapter  extends ArrayAdapter<profiles> {
 Context context;
 Arraylist<profiles> profileArraylist;

 public profiles_adapter(Context context, int resourceId, ArrayList<profiles> 
 item) {

this.context=context;
this.profileArraylist = item;
 }
Public View getView(int position, View convertView, ViewGroup parent) {

final profiles profile = profileArraylist.get(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());
 }