我有一個recycleView,我設置了它的適配器,但我不知道它爲什麼沒有顯示任何內容。我認爲我做的我做了,每次我都用它同樣的事情......下面是代碼:RecycleView不顯示結果
佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/iron">
<android.support.v7.widget.RecyclerView
android:id="@+id/appointment_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
的活動:
這裏我用一個主持人,給我一個清單。我調試它,它的工作原理。
public class AppointmentDateSelectionView extends NotificationActivity implements MVP.View {
RecyclerView dayAppointments;
AppointmentDateSelectionPresenter presenter;
private ListAdapter adapter;
List<ResponseAppointmentHours> availableHours;
private int idDoctor;
@Override
protected void onCreate(@Nullable Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.activity_appointment_date_selection);
BaseManager<String> managerToken = new TokenManager(getApplicationContext());
dayAppointments = (RecyclerView) findViewById(R.id.appointment_list);
Intent i = getIntent();
idDoctor = i.getIntExtra(Params.INTENT.ID_DOCTOR, 0);
presenter = new AppointmentDateSelectionPresenter(managerToken, idDoctor);
presenter.onViewCreated(this);
presenter.initialize();
dayAppointments.addItemDecoration(new SimpleDividerItemDecoration(this));
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 5);
}
@Override
public void setDoctorAppointmentList(List<ResponseAppointmentHours> hoursList) {
availableHours = hoursList;
adapter = new ListAdapter(availableHours);
dayAppointments.setAdapter(adapter);
dayAppointments.setItemAnimator(new CustomDefaultItemAnimator());
dayAppointments.setHasFixedSize(true);
adapter.notifyDataSetChanged();
}
的ListAdapter:
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ItemViewHolder> {
private final OnDeleteClickListener listener1;
private static List<ResponseAvailableHours> list = new ArrayList<>();
static class ItemViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.availability_from)
TextView availabilityText;
@BindView(R.id.delete)
ImageView delete;
ItemViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
public void bind(final ResponseAvailableHours item, final OnDeleteClickListener listener) {
delete.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
list.remove(item);
listener.onItemClick(item);
}
});
}
}
ListAdapter(OnDeleteClickListener listener1, List<ResponseAvailableHours> data) {
this.listener1 = listener1;
list = data;
}
@Override
public ListAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.avaliability_item, parent, false);
return new ItemViewHolder(v);
}
@Override
public void onBindViewHolder(ListAdapter.ItemViewHolder holder, int position) {
final ResponseAvailableHours hour = list.get(position);
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
try {
SimpleDateFormat newFormat = new SimpleDateFormat("HH:mm");
Date endDate = formatter.parse(hour.getTimeEnd());
Date iniTime = formatter.parse(hour.getTimeIni());
String available = "Cada " + WeekDays.getDays(hour.getWeekday()) + " de " + newFormat.format(iniTime) + "h a " + newFormat.format(endDate) + "h";
holder.availabilityText.setText(available);
} catch (ParseException e) {
e.printStackTrace();
}
holder.bind(hour, listener1);
}
@Override
public int getItemCount() {
return list.size();
}
在活動當它從adapter = new ListAdapter(availableHours);
經過的ListAdapter方法正確地解僱,但沒有別的正在發生的事情。