Я хочу отображать объекты: 2-й и 3-й из первого массива следующих ответов JSON.Но RecyclerView.adapter ничего не показывает
[
[
449613483,
"-6.103334",
"106.987316",
"2019-05-16T00:00:09.000+07:00",
0
],
[
449614907,
"-6.103334",
"106.987316",
"2019-05-16T00:03:08.000+07:00",
0
],
....
]
PlaybackFragment
mApiService.getHistory(token,units,startDate,endDate)
.enqueue(new Callback<ArrayList<Object>>() {
@Override
public void onResponse(@NonNull Call<ArrayList<Object>> call, @NonNull Response<ArrayList<Object>> response) {
progressBar.setVisibility(View.GONE);
if (response.isSuccessful()){
assert response.body() != null;
playbackList=response.body();
for (int i=0; i<playbackList.size(); i++) {
first = playbackList.get(0);
firstList.add(first);
}
Log.d(TAG,"Response : "+playbackList);
Log.d(TAG,"First : "+first);
customAdapter= new CustomAdapter(playbackList, getContext());
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(customAdapter);
}
}
@Override
public void onFailure(@NonNull Call<ArrayList<Object>> call, @NonNull Throwable t) {
progressBar.setVisibility(View.GONE);
}
});
А это мой CustomAdapter
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {
private ArrayList<Object> playbackList;
private ArrayList<Object> firstList = new ArrayList<>();
private Object first, last;
private Context context;
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView lat, lng, address;
CardView cv_list_journey;
public MyViewHolder(View view) {
super(view);
lat = view.findViewById(R.id.tv_lat);
lng = view.findViewById(R.id.tv_lng);
address = view.findViewById(R.id.tv_address);
}
}
public CustomAdapter(ArrayList<Object> playbackList, Context context){
this.playbackList=playbackList;
this.context=context;
}
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_view, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
try {
for (int i=0; i<playbackList.size(); i++) {
first = playbackList.get(0);
firstList.add(first);
String lat1 = String.valueOf(firstList.get(1));
String lng1 = String.valueOf(firstList.get(2));
double startLatitude = Double.valueOf(lat1);
double startLongitude = Double.valueOf(lng1);
List<Address> addresses = geocoder.getFromLocation(startLatitude,startLongitude, 1);
String address = addresses.get(0).getAddressLine(0);
holder.lat.setText(lat);
holder.lng.setText(lng);
holder.address.setText(address);
}
holder.cv_list_journey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
} catch (Exception e) {
Log.e("Error occured in: ", this.getClass().getName());
}
}
@Override
public int getItemCount() { return first == null ? 0 : first.size(); }
}
Я не понимаю, почемуадаптер не может получить массив.Ошибка RecyclerView: адаптер не подключен;пропускающий макет