Monday 15 February 2010

android - How can I efficiently transfer checked items from a listview to another activity when data is supplied by a Content Provider -



android - How can I efficiently transfer checked items from a listview to another activity when data is supplied by a Content Provider -

the title doesn't cover all. it's next utilize case:

select bunch of items in listview move next activity show selected items in new activity in listview if user decides move previous section same items should still checked

if using pojos add together onitemclicklistener listview , add together items array each time user clicks item , ship array new activity. listview populated using loader gets info contentprovider , puts in simplecursoradapter.

in current state can think of few possible solutions:

1) add together column relevant table of objects in listview. each time user selects item column updated indicate selected.

this has few advantages:

once have moved next activity can query selected items. when moving previous activity can utilize column show selected view.

but few disadvantages:

requires update each time item clicked, triggering loader. requires custom adapter uses state of new column decide whether should or should not shown checked. perchance creating delay between clicking item , showing checked. the default check options in listview unusable

2) track ids of checked items (using onitemclickedlistener or getcheckeditemids) , pass them next activity. in new activity create selection argument of "id = ? or " repeating n times (and excluding lastly or) , utilize given array selection arguments.

advantages:

no need maintain updating database. no columns in database. item checking has no delay. default check options listview still usable

disadvantages:

moving previous activity harder. homecoming list of selected item ids, listview has alternative setitemchecked takes position. i'd have iterate on entire adapter find positions of items , set them checked.

i'm capable of implementing them without hassle. @ moment i'm gravitating towards sec option.

so have next questions:

is there easier way in android. what way recheck items (see disadvantage in sec suggestion , if there's no improve way it).

this listview search function 1 time again create bit harder because if i'm not mistaken filtering resets every time. i'd have recheck items every time (ideally during filtering).

your disadvantage "requires update each time item clicked, triggering loader." not quite true trigger if contentprovider calls notifychange have not phone call notifychange in specific cases

and pressing going previous activity shouldn't hard if explicitly phone call finish() on activity, otherwise should able save state onsaveinstancestate

either way utilize 3rd approach , wouldn't utilize sec activity maintain within single activity utilize pearhaps 2 fragments 1 initial check list , sec 1 sec preselected list , utilize callbacks , allow activity manage all,is possible utilize case ?

android android-activity android-listview android-contentprovider

No comments:

Post a Comment