所以我有一个recyclerview,在我的recyclerview中我有物品。如果我删除了我的Recyclerview中的所有可见项目,那么仍然会留下一个基本上是"隐藏"这是什么原因?我相信这很容易解决但是它是什么?
public class AdapterTags extends RecyclerView.Adapter<AdapterTags.ViewTags>{
private LayoutInflater mLayoutInflater;
private ArrayList<Search> ListSearch=new ArrayList<>();
public AdapterTags(Context context){
mLayoutInflater=LayoutInflater.from(context);
}
public void setTagsList (ArrayList<Search> ListSearch){
this.ListSearch=ListSearch;
notifyItemRangeChanged(0,ListSearch.size());
}
@Override
public ViewTags onCreateViewHolder(ViewGroup parent, int viewType) {
View view= mLayoutInflater.inflate(R.layout.fragment_tags, parent, false);
ViewTags viewholder=new ViewTags(view);
return viewholder;
}
@Override
public void onBindViewHolder(ViewTags holder, int position) {
final Search currentTags=ListSearch.get(position);
holder.mSearchText.setText(currentTags.getMtitle());
holder.mAnswerPointsSearch.setText(currentTags.getMkey());
holder.mSearchId.setText(currentTags.getMid());
holder.mCourseId.setText(currentTags.getCourseId());
}
@Override
public int getItemCount() {
return ListSearch.size();
}
class ViewTags extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView mSearchText;
private TextView mAnswerPointsSearch;
private TextView mSearchId;
private TextView mCourseId;
public ViewTags(View itemView){
super(itemView);
mSearchText=(TextView)itemView.findViewById(R.id.SearchText);
mAnswerPointsSearch=(TextView)itemView.findViewById(R.id.AnswerPointsSearch);
mSearchId=(TextView)itemView.findViewById(R.id.SearchId);
mCourseId=(TextView)itemView.findViewById(R.id.CourseTextView);
}
致电活动
private void JsonRequestMethod() {
mVolleySingleton = VolleySingleton.getInstance();
mRequestQueue = mVolleySingleton.getRequestQueue();
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, URL_ANSWER, (String) null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
ListSearch = parseJSONResponseQuestion(response);
mAdapterDashBoard.setTagsList(ListSearch);
System.out.println(response);
System.out.println("it worked!!!");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println(error);
}
});
mRequestQueue.add(request);
}
答案 0 :(得分:1)
我建议您通过构造函数传递项目,而不是在setItems时立即调用notifyItemRangeChanged()。您还应该检查getItemCount方法中的项目是否为null,因为如果是,您的应用程序将崩溃。希望这会有所帮助。