Setting listpicker to original list w/o the before picking handler

Hello all,

Once again I am having trouble with listpickers.
In December, I was trying to get a listpicker to change lists and stay open. Eventually, I found out that couldn't happen and decided to switch between 2 listpickers, going back and forth as the lists change. I then ran into another problem, which was that the first listpicker was not switching lists, and it was only showing the preset list. I figured out that it was because of the set.listpicker block in the before picking event handler. Now, how do I get the listpicker to reset to the original list when the user clicks on it again without using that event handler?

Here's the code- the listpickers are supposed to switch back and forth, and then list1 is supposed to reset to the original list after the user is done picking.

Any suggestion for what blocks to use?

You could use this sample app, if you replaced its three column table with your own link classifications and links.
Columns 1 and 2 are for navigation.
The stack variable is for backtracking.

1 Like

@ABG Thanks for your help. Here's my solution:
I made the blocks for list 1. After picking and list 2. After picking into 1 big procedure with the parameters Selection (list selection), Elements (list's elements), and Index (Selection Index). I put a list1.beforepicking handler down with an if statement with a setlist1.elements block inside, setting list.elements to the original list inside if global listlogic is true. At the beginning of each branch, I made the variable list logic false, and at the end of each branch i made the variable listlogic true again.
This makes it so the list is reset to the original list every time it is done w/o glitches





Works so far. :crossed_fingers: I am so proud of this....
@ABG Any advice or suggestions?

Out of curiosity, I loaded your procedure and expanded it fully.
It's a whale.
If you stay in this game, expect to learn to cut whales into sushi.

2 Likes

@ABG Any way to reduce it? I've just started to learn this type of coding this year. I'm taking AP Comp. Sci. so basically I'm a newb to this.

And you can upload blocks from their image on ai2... how? Magic?

There are techniques in some of the books in

namely Chapter 1 of
http://web.mit.edu/alexmv/6.037/sicp.pdf
but beware, that book is best eaten in small bites.

If you do the download right, like you did, without editting the image, you can drag the .png file into a Blocks Editor workspace and AI2 will use the hidden text in the file to recreate the blocks.

I save .png files of all my reusable procedures, by procedure name, to avoid having to recode them in other projects.

2 Likes

@ABG Wow. That's smart. I might do that for code for a universal theme.
And thanks for the pdf. You've been really helpful.

@ABG I was just going through the blocks for the listpickers and I saw this block
component_event.

  • Would the list be automatically be reset to the original list if put the setlist1.elements block in there every time I click on it?
  • And it wouldn't reset the list when it switches between lists like the list1.beforepicking event handler would do?

Thanks,

NetMinderNo.9Apps

I have never used this event.

I usually use the BeforePicking event to load Elements on the fly.

GotFocus()

Indicates the cursor moved over the ListPicker so it is now possible to click it.

This looks like it is intended for eye candy, to help the user see which component is currently under his finger and help him see if it is okay to click there. For such an event I would temporarily increase font size in that component.

1 Like

See here

I believe this block is a hangover from previous times also, and not functional in the way it works for a textbox

1 Like

Regarding the Before Picking event, this is most useful for cases when you need to change the available Elements depending on run time factors.

For example, say you sell clothing by mail.
Your order form has these list pickers:

  • Category (shoes/shirts/pants)
  • Material (leather/flannel/khaki/suede)
  • color (red/black/brown/white)
  • size (depends on item and stock availability)

As the customer Selects from each List Picker going down the list, you need to refill the Elements of each List Picker going down the list to reflect what you sell and what you still have in stock (i.e. size 13 brown leather shoes)

1 Like

@ABG and @TIMAI2. I'll look into this further, and big thanks for the helpful explanations.

@ABG and @TIMAI2, I could also put down a button and make the listpicker not visible. I could put a setlist1.elements block in it and a calllist1.open block after that. I think it would work in theory, as long as I make its image the one I'm using for the current listpicker, but I don't know for sure. What do you guys think?

Edit: Like this ↓ (the x is because it was a duplicate event handler)

Try it, and let us know if you got it to work.

1 Like

@ABG Both worked fine. I tried out the gotfocus component and the button, and both reset the listpicker to the first list. I am going with the button, just my preference. I haven't really worked with the got focus components yet, but i think they might come in handy for situations like these.

Do you know if the dev. are going to take it out? Because, as others have said,

and it might not be necessarily needed, since androids have updated past that point.

@TIMAI2 What do you think?

About what ?

About how i solved my problem. Which way would you use? And what is your opinion on it?

Sorry, I would not have started from there :wink:

2 Likes

Put a sample of your application here in the aia file. After testing, maybe some better solutions will emerge.
Without seeing what the application is doing, it's hard to give advice. I only saw that you are using list view to change application settings.

2 Likes