Languages

Menu
Sites
Language
Get CustomItem in ListView

Hi all,

How to get CustomItem of ListView if I know its index in the list? 

Something like: " CustomItem*  pCustomItem =  m_pListView->GetCustomItem( int index )"  

This can be done in Tizen? Or is it extremely difficult for Tizen?

  

 

Responses

13 Replies

AFAIK, you can't get the customitem!!

sudarshan madabusi

Even I am stuck with a similar issue where I need reference of a particular custom item in list view.

It is sad that Tizen doesn't provide a way to get a particular custom item's reference.

Its messy to store the pointer references at our end and handle its life cycle, it would be design wise cleaner if this comes from the framework.

Alex Dem

Hi,
I understand it is not so comfortable but you could use:   __pListView->RefreshList(index,LIST_REFRESH_TYPE_ITEM_MODIFY);
to reconfigure Item with desired index inside reimplemented IListViewItemProvider::CreateItem().
Alexey.

sudarshan madabusi

Hi,

Yes, as you said we can use RefreshList() but it would be an overkill for my usecase.

I just need to read the content in a particular custom item, for which recreating (delete and creation of) the custom list item would be an overkill.

And moreover if I am filling my custom item based on a list from a web server then recreating would mean fetching again unless I am storing it locally.

It would be convenient if the value is accessible from framework without storing it locally.

~sudarshan

Alex Dem

Hi,
No such api but you could store every pointer to every Custom Item of ListView inside CreateItem(int index, int itemWidth) during ListView creation/recreation.
something like this:
    CustomItem* pItem = new CustomItem();
__pItem[index]=pItem;
After this you are able to use AddElement/RemoveElement e.t.c. APIs for every item anywhere.
On Refresh/Update of ListView  your array could be automatically modified with valid pointers.
p.s. Some difficulties could be with how to set __pItem[] array's size if list size dinamically changed.
Alexey.

Alex Ashirov

Hi Alex,

Please don't worry about array's size. It's possible to use some dynamic collection (e.g. Tizen::Base::Collection::ArrayList) for this purpose instead of a flat array.

Slawek Kowalski

Why do you need to get CustomItem? Use index which point to your model. There you find all data

you need.

 

CustomItem only displays your model - it is UI element and used internally by system.

 

regards

 

 

 

Alex Ashirov

Hi,

I agree. I also, can't find any case when such API may be useful.
 

sudarshan madabusi

Hi,

My usecase is to display a list of strings fetched from a web service. This list is huge. It is around 1000 strings.

And we want to allow user to delete few items from the list (at random locations) and once user deletes the item we would remove the item from the list which is displayed.

Similarly user can keep doing this any number of times and also decide to undo everything and display the original list.

In this scenario if framework does not provide a way to identify a string at particular location then we would either have to maintain 2 sets of the string list or maintain a map of original index and reordered index.

If framework provides a way to access content in a particular list item it would have been easier.

In other mobile platforms we were able to access the content in a particular list ( custom) item, so it was better in terms of memory overhead and extra processing needed.

~sudarshan

 

Slawek Kowalski

Actions like remove/insert/add do on your model. You can use ArrayList to store your strings or any Object you want to.

Just use two ArrayList-s: 1st with original strings and 2nd for working data - used by ListView. After user select Undo

copy 1st list to 2nd one. It is not only way to solve it. Just one of many ideas I suppose.

 

Never/ever store pointers to CustomItems. It is used by system so you never know what happens with it.

 

 

sudarshan madabusi

Yes, Thats how currently we are doing it.

But as you know memory is a limited resource in mobile devices. And we did not want to duplicate data in 2 arrays.

 

~sudarshan

Alex Ashirov

Hi,

IMHO it’s quite general practice to have copies of the same data on the both model and UI sides. According to the model-view pattern we can have several representations (views) of single model. This is why most of UI elements make copies of data passed them via methods like SetText() etc. In our case, CustomItems stores its own copies of data provided them during construction.

Slawek Kowalski

I think you shouldn't load all strings at once. Try to construct some pageing engine. E.g. load first 100 strings/items

after that next 100 and so on. It is similar to browser pageing.

 

This approach covers a few advantages:

- helps to avoid memory issue,

- ListView for e.g. 100 items will be rendered faster than for 1000+,

- limit Internet connection and battery drain

 

And extra tip: usually users view only the newest data.

 

regards