仅当我在Messenger中发送消息时,才会加载recyclerView。 当我执行该应用程序时,不会出现recyclerView。 在下面的代码中,我将代码放入适配器。
query1.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
description.setText(object.getString("Description"));
schedule.setText(object.getString("Schedule"));
adress.setText(object.getString("Adress"));
JSONArray array = object.getJSONArray("Classes");
for (int i = 0; i < array.length(); i++) {
try {
JSONObject jsonObject = array.getJSONObject(i);
Classes data = new Classes(jsonObject.getString("Aula"), jsonObject.getString("Horario"), jsonObject.getString("Preço"));
data_list.add(data);
} catch (JSONException e1) {
}
}
} else {
Log.i("Gym", "Error " + e.getMessage());
}
}
这是我的适配器: 我正在使用ParseServer,但这不起作用...
public DataAdapter(Context context, List<Classes> classes){
this.context=context;
this.classes= classes;
}
@Override
public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_row,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.aula.setText(classes.get(position).getAula());
holder.preco.setText(classes.get(position).getPreco());
holder.horario.setText(classes.get(position).getHorario());
}
@Override
public int getItemCount() {
return classes.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView aula;
private TextView preco;
private TextView horario;
public ViewHolder(View itemView) {
super(itemView);
aula = (TextView)itemView.findViewById(R.id.aula);
preco = (TextView) itemView.findViewById(R.id.preço);
horario= (TextView) itemView.findViewById(R.id.horario);
}
}
有人可以帮我吗?
答案 0 :(得分:0)
我错过了适配器中的notifyDataChanged。
query1.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
description.setText(object.getString("Description"));
schedule.setText(object.getString("Schedule"));
adress.setText(object.getString("Adress"));
JSONArray array = object.getJSONArray("Classes");
for (int i = 0; i < array.length(); i++) {
try {
JSONObject jsonObject = array.getJSONObject(i);
Classes data = new Classes(jsonObject.getString("Aula"), jsonObject.getString("Horario"), jsonObject.getString("Preço"));
data_list.add(data);
adapter.notifyDataSetChanged(); //I added this
} catch (JSONException e1) {
}
}
} else {
Log.i("Gym", "Error " + e.getMessage());
}
}