Where to download data for the adapter? In action? or in the adapter?

You must have an adapter to view the list. To fill in the list items, you need data. Now here is the question:

  • Is it a good idea to load data into a custom adapter?
  • or is it better to load data into action and transfer it to the adapter?
  • or their best way to achieve this?
+4
source share
3 answers

I got the best answer to this question:

  • prepare your data in Activity, and then send it to your adapter. It can be loading data through AsyncTask or from SQLite or something else.
  • In the adapter, load data through AsyncTask or from SQLite or something else.

But the best option is to load the data into the Activity and use it in the Adapter. This will help you make your codes cleaner and it will give you more flexibility to manage your data. But in some situations, you might consider preparing data in the Adapter; if you find it difficult to load it into Activity.

Both work great, it's up to you what you think.

0
source

there is only one question with three options

 is this a good idea to download the data in custom adapter or better is download data in activity & pass it to adapter their is any better way to achieve that ? 

Create an AsyncTask from Activity and set the data to adapter from onPostExecution callback function

good tutorial link1

2- Download ListView in the background AsyncTask

+4
source

You can load in any activity class, then send data via Broadcast, edit your adapter and finally update the list of adapters ie by calling:

 adapter.notifyDataSetChanged(); 
0
source

All Articles