ParseQueryAdapter получает данные, но не показывает их фрагмент
Я пытаюсь показать список с именем, датой и местом событий. Для этого я создал ParseQueryAdapter и ViewHoder, и в журнале я получаю эти данные с сервера, но их нет на экране.
Это мой фрагмент.
public class EmbreveFragment extends Fragment {
private List<Corrida> listaCorrida = new ArrayList<>();
private RecyclerView recyclerView;
private CorridasAdapter mAdapter;
public static EmbreveFragment getInstance(){
EmbreveFragment embreveFragment = new EmbreveFragment();
Bundle extraArguments = new Bundle();
embreveFragment.setArguments(extraArguments);
return embreveFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_embreve, container, false);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Corridas");
query.setLimit(15);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e ==null){
for (int i=0; i<objects.size(); i++){
Corrida corrida = new Corrida();
corrida.setNome(objects.get(i).getString("nome"));
corrida.setData(objects.get(i).getString("dataCorrida"));
corrida.setHora_largada(objects.get(i).getString("horaLargada"));
Log.i("nome", corrida.getNome().toString());
Log.i("nome", corrida.getData().toString());
Log.i("nome", corrida.getHora_largada().toString());
listaCorrida.add(corrida);
}
}else {
ParseErros parseErros = new ParseErros();
String erro = parseErros.getErro(e.getCode());
Log.i("erro:", erro);
Toast.makeText(getActivity(), erro, Toast.LENGTH_LONG).show();
}
}
});
recyclerView = view.findViewById(R.id.recycler_view2);
mAdapter = new CorridasAdapter(listaCorrida);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
recyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
//prepararListaCorrida();
return view;
}
}
Это мой зритель
public class CorridasAdapter extends RecyclerView.Adapter<CorridasAdapter.MyViewHolder> {
private List<Corrida> listaCorrida;
public class MyViewHolder extends RecyclerView.ViewHolder{
public TextView nomeCorrida, dataCorrida, horaLargada;
public MyViewHolder(View view){
super(view);
nomeCorrida = view.findViewById(R.id.id_nomeCorrida);
dataCorrida = view.findViewById(R.id.id_dataCorrida);
horaLargada = view.findViewById(R.id.id_HoraLargada);
}
}
public CorridasAdapter(List<Corrida> listaCorrida){
this.listaCorrida = listaCorrida;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.corridas_lista, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Corrida corrida = listaCorrida.get(position);
holder.nomeCorrida.setText(corrida.getNome());
holder.dataCorrida.setText(corrida.getData());
holder.horaLargada.setText(corrida.getHora_largada());
}
@Override
public int getItemCount() {
return listaCorrida.size();
}
}
И XML-код элемента и фрагмента.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="@dimen/row_padding_vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/row_padding_vertical">
<TextView
android:id="@+id/id_nomeCorrida"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textColor="@color/title"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_dataCorrida"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/id_HoraLargada"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/id_dataCorrida"
android:textColor="@color/year" />
</RelativeLayout>
Фрагмент
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.crdev.papaleguas.fragment.RecentesFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</RelativeLayout>
Из журнала я получаю данные, но на экране ничего не отображается. Кто-нибудь может помочь другу?