2014년 12월 31일 수요일

Listview selectionindex problem


Well, I read about previous problems with the listview selectionindex giving incorrect indexes when search filter is used. So, in order to overcome this:

- I defined a variable named selectedindex.
- I run an if block to see if the selection(which is supposed to return the selected text) is in one of my three lists ( these are the listview elements lists)
- then in the then part of the if block, I get the index of the selected item by searching the selection in the list.
- and to test it, I ask to name a textbutton to my variable selectedindex.

now in theory, this should look for the index of the selected text in three tables, when it finds it, it should set the textbutton text to the correct index. But, when I use it without the searchfilter, it works perfectly, and when I use the searchfilter, it still returns 2 when I select the second element in the filtered list. 

Why does it happen? I have no idea. I thought that maybe the searchfilter was playing around with my list when we enter text in the searchfilter, (for example, it might remove items temporarily and still show the same list with filtered items) but before that point, I have another variable called currentlist, which is set to one of the three lists before to show the elements of the currentlist, so if it were playing, it would mess with my currentlist variable, not the actual one(or would it?).

Whatever, I'm stuck. Any suggestions on how to make that block work? All I can think of is that I can generate three more lists with names and get the index from there (but I don't wantto, since the current list tables are the tables with just the names, so I'd have duplicate tables, which would be confusing during the update..)


--
If you want to avoid listview filtering, try this approach ... Build Your Own DB - Part 1
Here's a doc on using lists of list filtering with
an example app using a spinner, which acts similarly to
a listview.

The general idea is to use general purpose selection routines to
feed the listview from a pipeline of temporary tables.

Maybe it will help you.

--
it seems to be using the filterbar in the listview is completely broken, actually @Bhagavati already reported it Nov 25 here Filter Bar in List View does not seem to work even with Selection...
remember, in the listpicker at least you get the correct selection after selecting an item, but not in the listview anymore

screenshots and example project attached
I first filtered for b, then I selected b2 from the list
in the blocks editor as result, I get a2 (which is wrong and should be b2)
the selection index as we know from the listpicker you also can't use (this is 2 in  the example and should be 4)

--
Thanks for reporting this.   I've filed it as a bug.  

--
@Taifun, Regarding the statement you made on GitHub [1], I know how to accomplish it. However, that's not the point. SelectionIndex is useless regardless and, to my idea, is only good for static short list that don't provide user with sorting, shuffling, adding, removing items from the list. If such features as sorting, shuffling, inserting items within lists were available, how would original SelectionIndex be used or be useful?

Please take a look at the jQuery Mobile listview as an example, how it should be done http://jquerymobile.com/demos/1.2.0/docs/lists/index.html.

--
As you know, often there are 2 or more lists connected via the selection index, which means, the selection index is essential for this kind of functionality, see my quiz example https://puravidaapps.com/quiz.php   quizquiz.aia

If the listpicker temporarily sorts or filters a list, the original list remains the same and the original index should be provided after picking an item. Same, if we will have a shuffle option one day.

If we will have a functionality to add or remove an item in the listpicker directly one day (for example after left or right swipe?), the original list would be changed and the index of the new list should be provided after picking an item.

Actually we do not have to reinvent the wheel, therefore I suggested to take a look at the jQuery Mobile listview as an example, how it is done there http://jquerymobile.com/demos/1.2.0/docs/lists/index.html.

--
I'm looking into extending listview component to support not just text. 

Somehow, I find this bug described here has been reported 11 months ago.  I feel I need to help fix this bug firstly to move on.

I've tried Taifun's aia, to be honest, from the android api point of view, the selection index makes perfect sense for me. 
It is only the index in the current list rather than before filtering.

I've also checked Hossein's pull request on github which is trying to return the index in the parent list before filtering.see here: https://github.com/mit-cml/appinventor-sources/pull/199/files#r22332834

My opinion is to keep what it is right now to keep consistent to android api's list view functionality. 

Hope this issue is going to be fixed sooner.  I could help if anyone needs.

--

댓글 1개:

  1. Any new solution to that bug? When filtered, selectionindex giving incorrect indexes :-(

    답글삭제