0

Is it possible to load all items in the adapter at once?

I am using a CursorLoader, a ListView and a Cursor adapter, the items in the the adapter are loaded with scrolling. I know I have only few simple items (about 10) so I do not have performance problems

Thanks

Víctor Martín
  • 2,680
  • 2
  • 39
  • 80
aorlando
  • 662
  • 5
  • 20
  • what is your actual question? – JoxTraex Aug 27 '15 at 10:04
  • 1
    if you are already knowing what will be the content of your listview items, better set it in a arraylist and define adapter using that. there's no need to use cursor – karan Aug 27 '15 at 10:07
  • @Karan Mer: I need to change my app structure because you do no know a valid solution? no thanks, my question is clear and what I need, thanks – aorlando Aug 27 '15 at 10:14
  • `"my question is clear"` actually there is no question here... at least JoxTraex and me cannot see it – pskink Aug 27 '15 at 10:18
  • is it not enough as in the title? "load all items in the adapter all at once". Ok I reply in the body ... :-| – aorlando Aug 27 '15 at 10:20
  • no man, it doesn't help much: what do you mean "load at once" ??? – pskink Aug 27 '15 at 10:23
  • @pskink: if is not clear please read the comment to Victor_J_Martin – aorlando Aug 27 '15 at 10:40
  • If you are trying to load all entries of your ArrayList or Cursor into ListView, then you are trying to break the whole purpose of a ListView/GridView. As you may know, the functionality of ListView is as such to "load only what you see, with buffer". So, may be you should implement your own view to handle this kind of scenario. May be trying to experiment with ListView in this scenario, might cause you problems at a later stage. – Vamsi Challa Aug 27 '15 at 10:42
  • 1
    If you only have 10 items, i guess, creating the views and adding them to layout(scrollview maybe) dynamically will be more easier, than fighting with ListView. – Vamsi Challa Aug 27 '15 at 10:46
  • @Vamsi, load all items in a list and add a CardView in a ScrollView for every item, so I can avoid to use the cursor adapter and scan only once the cursor... It is not the exact answer I am looking for but It is a nice solution – aorlando Aug 27 '15 at 10:54

1 Answers1

1

Read this Populating-a-ListView-with-a-CursorAdapter or this Android Cursor Example

If you want to use an ArrayList (getted from Populating a ListView using an ArrayList):

lv = (ListView) findViewById(R.id.your_list_view_id);

     // Instanciating an array list (you don't need to do this, 
     // you already have yours).
     List<String> your_array_list = new ArrayList<String>();
     your_array_list.add("foo");
     your_array_list.add("bar");

     // This is the array adapter, it takes the context of the activity as a 
     // first parameter, the type of list view as a second parameter and your 
     // array as a third parameter.
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
             this, 
             android.R.layout.simple_list_item_1,
             your_array_list );

     lv.setAdapter(arrayAdapter); 
Community
  • 1
  • 1
Víctor Martín
  • 2,680
  • 2
  • 39
  • 80
  • thanks, the use of the CursorAdapter in the second link is the same than mine. The bindView method is called every time I scroll my listview, and new data from the cursor are loaded. What I need is (something like) to load all items in the first call of bindView, I do not know if is there something available in the ListView or in the CursorAdapter object – aorlando Aug 27 '15 at 10:39
  • You can create a List with the data of the Cursor and use this List. I've edited my answer. Look it. – Víctor Martín Aug 27 '15 at 10:43
  • useful, something similar is my actual solutions but in this way I need to scan the cursor data two times, one to populate the list and the other scan will be performed from the CursorAdapter... I am sure we can do better and use only the CursorAdapter scan :) – aorlando Aug 27 '15 at 10:47