我一直在研究一个搜索功能,这将使我能够在我的 RecyclerView 中搜索数据。单击搜索图标时,我的应用程序崩溃。经过一些调试后,我发现了问题,似乎无法清除或向新列表添加信息。
适配器类.java
public class JobAdapter extends RecyclerView.Adapter<JobAdapter.ViewHolder> implements Filterable {
private OnJobClickListener mListener;
private List<Job> jobs;
private List<Job> jobsListFiltered;
private static final String LOG_TAG = JobAdapter.class.getName();
public interface OnJobClickListener {
void onJobClick(Job job);
}
public void setOnItemClickListener(OnJobClickListener listener) {
mListener = listener;
}
// Provide a reference to the views for each data item
// Provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView jobTitle;
public TextView companyName;
public TextView datePosted;
public ImageView companyLogo;
public View layout;
public ViewHolder(View itemView) {
super(itemView);
layout = itemView;
jobTitle = layout.findViewById(R.id.textView_job_title);
companyName = layout.findViewById(R.id.textView_company_name);
datePosted = layout.findViewById(R.id.textView_date);
companyLogo = layout.findViewById(R.id.imageViewLogo);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
Job currentJob = jobs.get(position);
mListener.onJobClick(currentJob);
}
}
}
});
}
}
}
萧十郎
相关分类