当前位置:网站首页>Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
2022-07-03 02:51:00 【Zafo】
problem :
I am getting data from server and then parsing it and storing it in a List. I get data from the server , Then parse it and store it in a list .I am using this list for the RecyclerView's adapter. I use this list for RecyclerView Adapter for .I am using Fragments. I'm using clips .
I am using a Nexus 5 with KitKat. I'm using KitKat Of Nexus 5.I am using support library for this. I'm using support libraries for this .Will this make a difference? Will this make a difference ?
Here is my code: (Using dummy data for the question) This is my code :( Use virtual data for the problem )
Member Variables: Member variables :
List<Business> mBusinesses = new ArrayList<Business>();RecyclerView recyclerView;RecyclerView.LayoutManager mLayoutManager;BusinessAdapter mBusinessAdapter;
My onCreateView()
: my onCreateView()
:
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Getting data from server getBusinessesDataFromServer(); View view = inflater.inflate(R.layout.fragment_business_list, container, false); recyclerView = (RecyclerView) view .findViewById(R.id.business_recycler_view); recyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(mLayoutManager); mBusinessAdapter = new BusinessAdapter(mBusinesses); recyclerView.setAdapter(mBusinessAdapter); return view;}
After getting data from server, parseResponse()
is called. After getting data from the server , call parseResponse()
.
protected void parseResponse(JSONArray response, String url) { // insert dummy data for demo mBusinesses.clear(); Business business; business = new Business(); business.setName("Google"); business.setDescription("Google HeadQuaters"); mBusinesses.add(business); business = new Business(); business.setName("Yahoo"); business.setDescription("Yahoo HeadQuaters"); mBusinesses.add(business); business = new Business(); business.setName("Microsoft"); business.setDescription("Microsoft HeadQuaters"); mBusinesses.add(business); Log.d(Const.DEBUG, "Dummy Data Inserted\nBusinesses Length: " + mBusinesses.size()); mBusinessAdapter = new BusinessAdapter(mBusinesses); mBusinessAdapter.notifyDataSetChanged();}
My BusinessAdapter: My business adapter :
public class BusinessAdapter extends RecyclerView.Adapter<BusinessAdapter.ViewHolder> { private List<Business> mBusinesses = new ArrayList<Business>(); // Provide a reference to the type of views that you are using // (custom viewholder) public static class ViewHolder extends RecyclerView.ViewHolder { public TextView mTextViewName; public TextView mTextViewDescription; public ImageView mImageViewLogo; public ViewHolder(View v) { super(v); mTextViewName = (TextView) v .findViewById(R.id.textView_company_name); mTextViewDescription = (TextView) v .findViewById(R.id.textView_company_description); mImageViewLogo = (ImageView) v .findViewById(R.id.imageView_company_logo); } } // Provide a suitable constructor (depends on the kind of dataset) public BusinessAdapter(List<Business> myBusinesses) { Log.d(Const.DEBUG, "BusinessAdapter -> constructor"); mBusinesses = myBusinesses; } // Create new views (invoked by the layout manager) @Override public BusinessAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Log.d(Const.DEBUG, "BusinessAdapter -> onCreateViewHolder()"); // create a new view View v = LayoutInflater.from(parent.getContext()).inflate( R.layout.item_business_list, parent, false); ViewHolder vh = new ViewHolder(v); return vh; } // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder holder, int position) { // - get element from your dataset at this position // - replace the contents of the view with that element Log.d(Const.DEBUG, "BusinessAdapter -> onBindViewHolder()"); Business item = mBusinesses.get(position); holder.mTextViewName.setText(item.getName()); holder.mTextViewDescription.setText(item.getDescription()); holder.mImageViewLogo.setImageResource(R.drawable.ic_launcher); } // Return the size of your dataset (invoked by the layout manager) @Override public int getItemCount() { Log.d(Const.DEBUG, "BusinessAdapter -> getItemCount()"); if (mBusinesses != null) { Log.d(Const.DEBUG, "mBusinesses Count: " + mBusinesses.size()); return mBusinesses.size(); } return 0; }}
But I don't get the data displayed in the view. But I didn't get the data displayed in the view .What am I doing wrong? What on earth did I do wrong ?
Here is my log, This is my diary ,
07-14 21:15:35.669: D/xxx(2259): Dummy Data Inserted07-14 21:15:35.669: D/xxx(2259): Businesses Length: 307-14 21:26:26.969: D/xxx(2732): BusinessAdapter -> constructor
I don't get any logs after this. I haven't received any logs since .Shouldn't getItemCount()
in adapter should be called again? You should not call... In the adapter again getItemCount()
Do you ?
Solution :
Reference resources : https://stackoom.com/en/question/1fo9F边栏推荐
- Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
- "Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b
- As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
- Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
- How to change the panet layer in yolov5 to bifpn
- Cancer biopsy instruments and kits - market status and future development trends
- Concrete CMS vulnerability
- xiaodi-笔记
- [shutter] banner carousel component (shutter_wiper plug-in | swiper component)
- Sqlserver row to column pivot
猜你喜欢
随机推荐
处理数据集,使用LabelEncoder将所有id转换为从0开始
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
HTB-Devel
vfork执行时出现Segmentation fault
二维格式数组格式索引下标连续问题导致 返回json 格式问题
[Hcia]No.15 Vlan间通信
sql server 查詢指定錶的錶結構
Super easy to use logzero
Informatics Olympiad one general question bank 1006 a+b questions
从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
Gbase 8C system table PG_ amproc
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
The difference between left value and right value in C language
Sqlserver row to column pivot
Xiaodi notes
sql server数据库添加 mdf数据库文件,遇到的报错
From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
Gbase 8C system table PG_ attribute
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常