Android Question Link Spinner Value when Clicking an Item in the ListView

Lyndon Bermoy

Active Member
Licensed User
Longtime User
I have a problem guys..

I have an application which needs to click an Item in the ListView from the database. And if I clicked the item in the listview, it will retrieve the value coming from the database into the text and spinner object.

In the EditText, the value retrieved was okay. But in the spinner, I can't retrieve the value of my particular column in the database to be displayed in the spinner (only one value must be displayed as i click an item in the listview).

Here's my code:

B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
 Main.clicksound.play
   Dim idvalue As String
Dim countIt As Int
Dim ID As String
idvalue = Value
countIt = idvalue.IndexOf("-") 'find location of sperator
idvalue = idvalue.SubString2(0,countIt) 'find first part of label text
ID = idvalue
Main.cursor1 = Main.sql1.ExecQuery("SELECT * FROM tblProduct where ID = '" & ID & "' ")
For i = 0 To Main.cursor1.RowCount - 1
Main.cursor1.Position = i
   txtMed.Text = Main.cursor1.GetString("BID")
   txtQty.Text = Main.cursor1.GetString("prodName")
   spnCategory.Add(Main.cursor1.GetString("prodCategory")) 'this code doesnt retrived the value of my category into the spinner
   txtCat1.Text = Main.cursor1.GetString("prodCategory")
   
Next
End Sub

Please help guys. Thanks! :)
 

Attachments

  • Screenshot_2016-01-23-17-39-44.png
    Screenshot_2016-01-23-17-39-44.png
    141.4 KB · Views: 275

Mahares

Expert
Licensed User
Longtime User
Did you try to invalidate the spinner:
B4X:
spnCategory.Add(Main.cursor1.GetString("prodCategory"))
spnCategory.Invalidate   'add this line
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tried your concept with this complete code and it worked for me. Check it out. You may have to Export your project as zip so someone can identify your problem:
B4X:
Sub Globals
    Dim MyLv As ListView
    Dim sp As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sp.Initialize("sp")
    sp.AddAll(Array As String("Erel", "Klaus", "DonManfred", "Johan Schoeman"))
    Activity.AddView(sp, 0, 600dip, 200dip, 50dip)
  
    MyLv.Initialize("MyLV")
    Activity.AddView(MyLv,0,0,100%x,575dip)
    For i=0 To 19
        MyLv.AddSingleLine2("B4A rocks" & i, "B4A" & i)
    Next

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub MyLV_ItemClick (Position As Int, Value As Object)
    Msgbox("I chose: " & Value,"Selected Item")
    sp.Add(Value)
    sp.Invalidate
End Sub
 
Upvote 0

Lyndon Bermoy

Active Member
Licensed User
Longtime User
I tried your concept with this complete code and it worked for me. Check it out. You may have to Export your project as zip so someone can identify your problem:
B4X:
Sub Globals
    Dim MyLv As ListView
    Dim sp As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sp.Initialize("sp")
    sp.AddAll(Array As String("Erel", "Klaus", "DonManfred", "Johan Schoeman"))
    Activity.AddView(sp, 0, 600dip, 200dip, 50dip)
 
    MyLv.Initialize("MyLV")
    Activity.AddView(MyLv,0,0,100%x,575dip)
    For i=0 To 19
        MyLv.AddSingleLine2("B4A rocks" & i, "B4A" & i)
    Next

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub MyLV_ItemClick (Position As Int, Value As Object)
    Msgbox("I chose: " & Value,"Selected Item")
    sp.Add(Value)
    sp.Invalidate
End Sub

The file size is 2mb sir so I can't attached.

Actually I get the value of the spinner if it was clicked. But my question sir is by clicking the rows in the Listview, the certain column for the Category will be
displayed in the spinner. That's what I meant sir.. The spinner doesnt need to be clicked to get the value but the listview will be clicked to get the value and displayed in the spinner.
 
Upvote 0
Top