Android Question Spinner question

anaylor01

Well-Known Member
Licensed User
Longtime User
How do you set the value for different values. Say you select the third value how can you change the text value for it.?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

mangojack

Expert
Licensed User
Longtime User
How do you set the value for different values. Say you select the third value how can you change the text value for it.?

I don't believe its possible to edit spinner items at runtime.

Maybe have a look at at @HotShoe 's Combo List lib Here ...

Or .. return to CustomListView where you can show some radio buttons ... small example attached.
 

Attachments

  • CLV Spinner Example.zip
    11.6 KB · Views: 364
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I guess I should explain what I am doing. When they select an item on the spinner they can rename it. By using an inputbox I want to take the value from the inputbox and replace the value in the spinner. So if they select SelectedIndex 3 then I replace the text value of the spinner at SelectedIndex 3 with the value they inputed into the inputbox. Oh and it will be working like this. They select a value. An inpubox opens up. They type the new value in the inputbox and press ok. Then select another value from the spinner and then another inputbox opens up and so on.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
To my knowledge, you really have to repopulate your spinner as DonManfred wrote earlier.
Just an example:
B4X:
Sub Globals
   Dim aSpinner As Spinner
   Dim aList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
   aList.Initialize
   aList.AddAll(Array As String("item 1","item 2","item 3"))
   aSpinner.Initialize("aSpinner")
   aSpinner.AddAll(aList)
   Activity.AddView(aSpinner,0,0,50%x,15%y)
End Sub

Sub aSpinner_ItemClick (Position As Int, Value As Object)
   Dim anInputDialog As InputDialog
   anInputDialog.Input=Value
   anInputDialog.Show("New Value:","Edit Pos" & Position & " - " & Value,"OK","Cancel","",Null)
   If anInputDialog.Response=DialogResponse.POSITIVE Then
     Dim newValue As String=anInputDialog.Input
     aList.InsertAt(Position,newValue)
     aList.RemoveAt(Position+1)
     aSpinner.Clear
     aSpinner.AddAll(aList)
   End If
End Sub
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
So if they select the first value which is index 0. The inputbox should open. The user should put a value in the inputbox. When the user clicks ok the value the user typed into the inputbox should now be the value at index 0.
Dim anInputDialog As InputDialog
anInputDialog.Input=Value
anInputDialog.Show("New Value:","Edit Pos" & Position & " - " & Value,"OK","Cancel","",Null)
If anInputDialog.Response=DialogResponse.POSITIVE Then
Dim newValue As String=anInputDialog.Input
aList.Initialize
aList.RemoveAt(Position)
Msgbox(Position,newValue)
aList.InsertAt(Position,newValue)
' spnNameTeams.Clear
Msgbox(aList,"alist")
spnNameTeams.AddAll(aList)
End If
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
You are not following above example .. You are trying to remove list item immediately after it has been initialized.
B4X:
'aList.Initialize             ' aList  initialize and populate before using (app start ??)     
aList.RemoveAt(Position)       ' <<<<<< Error !
Msgbox(Position,newValue)
aList.InsertAt(Position,newValue)
spnNameTeams.Clear
Msgbox(aList,"alist")
spnNameTeams.AddAll(aList)

also to avoid possible error, follow order of above example from @mc73 .. add new value to list before removing old value
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I get an invalid index 0, size 0 error. On this line. aList.RemoveAt(Position)

reread this line *Edited .. the example refered to was Your old code .
also to avoid possible error, follow order of above example from @mc73 .. add new value to list before removing old value

If still have Error ,show your changed code.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I get an invalid index 0, size 0 error. On this line. aList.RemoveAt(Position)

Do you still have error ? If you do then post some code.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Yeah. i am still getting the same error.
B4X:
   Dim anInputDialog As InputDialog
   anInputDialog.Input=Value
   anInputDialog.Show("New Value:","Edit Pos" & Position & " - " & Value,"OK","Cancel","",Null)
   If anInputDialog.Response=DialogResponse.POSITIVE Then
     Dim newValue As String=anInputDialog.Input
      aList.Initialize
      Msgbox(aList.Size,"")'0
aList.RemoveAt(Position)       ' <<<<<< Error !
Msgbox(Position,newValue)
aList.InsertAt(Position,newValue)
spnNameTeams.Clear
Msgbox(aList,"alist")
spnNameTeams.AddAll(aList)
   End If
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
So with a slider you can't say the value at this position equals this text?

Slider or Spinner ?

@anaylor01 , if you are still having problems post latest code or upload project . IDE Menu > File > Export as zip.

A spinner will work as you want if you follow @mc73 's example - post #6 .
 
Last edited:
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
#6 Is a spinner using a LIST. Can't you just say spn.position value = "Some Text"? I posted the code I am using and the error #14.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
#6 Is a spinner using a LIST. Can't you just say spn.position value = "Some Text"? I posted the code I am using and the error #14.
Have you read any of the previous post comments ?

You Can Not just say ... spn.position value = "Some Text".
You MUST Clear the spinner and re-add / re- populate the spinner with all the new values.

The code you posted was incorrect and we explained why . Did you not make any changes. ?
Show us your new code.

@mc73 example uses a list and works. ( only if you do it in the same order)

The new value of the edit text is add to the list.
The old value is removed from list.
The spinner is cleared of all entry's.
the spinner is filled again with all the lists contents.

Your code did not work because you initialized list immediately before trying to remove item from list (List is empty)

If you do not like this method .. return to using CustomListView. see example project #3
 
Last edited:
Upvote 0
Top