Pre-selecting Listview Row

243 views
Skip to first unread message

Dave Wynne

unread,
Jun 18, 2018, 6:30:57 AM6/18/18
to MIT App Inventor Forum
I have been trying to programatically select a row from a Listview by setting the selected index, however this does not appear to be causing the row to be selected (visibly). Is there a trick to this? I haven't been able to find any posts about this which suggests I am missing something obvious. Thanks.

SteveJG

unread,
Jun 18, 2018, 8:25:58 AM6/18/18
to MIT App Inventor Forum
A developer probably cannot  highlight a ListView line item using code.  The ability to do that is probably part of the code to 'touch', select and highlight the item.

What can be done with a ListView is here .     There is no Property to change the color of an item or to set focus to an item.  When an item is selected manually on a ListView, it sets the focus.  Than cannot be accomplished with a code Block. What you see is what you get Wynne.

There are various 'alternative' ways to 'simulate' a ListView described in the Forum.  Someone has created an extension that provides a similar display of List data.  You can search for them in the Forum using the Search for messages at the top of this screen. One of those options might work for you or you can live with the fact that you cannot programatically select a row from a ListView by setting the selected index and getting the item to highlight.    

If you use the index to select, what happens when you put a selection in a Label  ... Selection
Returns the text last selected in the ListView.
? The response, explains it all.


Regards,
Steve

SteveJG

unread,
Jun 18, 2018, 8:28:51 AM6/18/18
to MIT App Inventor Forum
Something you could try is to use the  any component blocks and try   set ListView1.Selection block.   Never tried that but you can experiment.


Regards,
Steve

Dave Wynne

unread,
Jun 18, 2018, 8:33:04 AM6/18/18
to MIT App Inventor Forum
Thanks for your reply - What confuses me is that there is the ability to set the selection index but there seems to be no effect from doing that (or at least no useful effect). The scenario I am trying to achieve is that I have a list view of items and I want to be able to re-order them by selecting a row and clicking on an up arrow button to move the row up the list (by moving the row in the underlying list) - when I refresh the listview to reflect the new order the selection disappears from the list and cannot be set. This is even more unfortunate since the row selected in this list dynamically displays row specific data. 

SteveJG

unread,
Jun 18, 2018, 8:53:07 AM6/18/18
to MIT App Inventor Forum
OK, so maintain a List that you CAN manipulate (create sub Lists).  Repopulate the ListVIew (which is mainly a graphical method of displaying a List with the ability to do some selecting) with what you want to display with code?

Recently (last week or so)  there was a post about Filtering a List that showed how to 'preserve' the original List indices; that may be what your are looking for.  https://groups.google.com/forum/#!searchin/mitappinventortest/filter$20list%7Csort:date/mitappinventortest/DHPkhOgtVBc/b1Ih9SW_AQAJ

Dave Wynne

unread,
Jun 18, 2018, 9:19:43 AM6/18/18
to MIT App Inventor Forum
Tried this and it doesn't appear to do anything that I could see. With regards to your other point, yes I can and am populating the data dependant on the list selection by using the underlying list but I need to provide visual feedback based on the list selection to show that the data displayed relates to the row selected (as it would when the list item is manually selected by the user

Chris Ward

unread,
Jun 18, 2018, 9:57:08 AM6/18/18
to MIT App Inventor Forum
Hello Dave

I'm not here today but if I was, I'd say you were looking for a means to highlight the ListView item selected programmatically, as you can when programming with Windows API.

App Inventor does not yet offer that, but there is an extension that possibly can: ColinTreeListView 

If that doesn't help, all is not lost because you can define an HTML list and display that in a WebView component. You can then do practically anything with the list. A little javascript function embedded in the page can tell App Inventor which list item was picked. 

Reply all
Reply to author
Forward
0 new messages