Android Question Reading data from .DB in Spinner Fault !

Itila Tumer

Active Member
Licensed User
Longtime User
I have Erkek/Bayan (which is sex) , I set in Spinner. But I cannot read , I dont' know why
wHEN I change the person . problem is the same.
Thanks.
 

Attachments

  • try.zip
    244.7 KB · Views: 137

Itila Tumer

Active Member
Licensed User
Longtime User
No , I don't
Just I cannot read properly.
If I click NExt or Before... It start to show man/women more than one .
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should fill the spinner only once with the two possibilities and not add the entries each time you select a new person.
When you select a person you should set the selected item in the spinner according to value for the given person.
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
most relative part is that

B4X:
ShowEntry(EntryIndex As Int)
...
.
.
Else
        ID = Activity2.IDList.Get(EntryIndex)        'get the ID for the given entry index
        'read the entry with the given ID
        Cursor1 = Activity2.SQL1.ExecQuery("SELECT * FROM persons INNER JOIN body ON persons.ID = body.IDbody WHERE ID = " & ID) 
        edtID.Text = ID                                                                                'display the ID
        For i=0 To Cursor1.RowCount-1
        Cursor1.Position = i                                                                    'set the cursor
        edtFirstName.Text = Cursor1.GetString("FirstName")        'read the value of the FirstName column
        edtLastName.Text = Cursor1.GetString("LastName")            'read the value of the LasstName column
        'edtSex.Text = Cursor1.GetString("Sex")
        edtBirthDay.Text = Cursor1.GetString("BirthDay")    'read the value of the City column
        edtBirthCity.Text = Cursor1.GetString("BirthCity")
        edtFatherName.Text = Cursor1.GetString("FatherName")
        edtBoy.Text = Cursor1.GetString("Boy")     
        'ImageView1.BLOB = Cursor1.GetBlob("Resim")
     
        spnCinsiyet.Prompt = "Cinsiyet"  
        spnCinsiyet.Add(Cursor1.GetString("Sex"))
     
        If Cursor1.GetString("Sex")= ("Erkek") Then
            spnCinsiyet.Add("Bayan")  // Women
            spinnerMap.Put("Bayan", "id 3")
        Else
            spnCinsiyet.Add("Erkek")  // Man
            spinnerMap.Put("Erkek", "id 2")
        End If
     
        Next
        Cursor1.Close                                                                                    'close the cursor, we don't it anymore
    End If
That part from that..

spnCinsiyet.Prompt = "Cinsiyet"
spnCinsiyet.Add(Cursor1.GetString("Sex"))

If Cursor1.GetString("Sex")= ("Erkek") Then
spnCinsiyet.Add("Bayan") // Women
spinnerMap.Put("Bayan", "id 3")
Else
spnCinsiyet.Add("Erkek") // Man
spinnerMap.Put("Erkek", "id 2")
End If



B4X:
Sub spnCinsiyet_ItemClick (Position As Int, Value As Object)
    Dim id As String
    id = spinnerMap.Get(Value)
End Sub
These are from EDIT Activity
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This is exactly the code part I was speaking of in post#5 !

In this part you add two items each time you call ShowEntry!
B4X:
spnCinsiyet.Add(Cursor1.GetString("Sex"))

If Cursor1.GetString("Sex")= ("Erkek") Then
      spnCinsiyet.Add("Bayan")
    spinnerMap.Put("Bayan", "id 3")
Else
    spnCinsiyet.Add("Erkek")
      spinnerMap.Put("Erkek", "id 2")
End If
From my post #5:
You should fill the spinner only once with the two possibilities
Put this code in Activity_Create:
B4X:
spnCinsiyet.Clear
spnCinsiyet.Add("Bayan")
spnCinsiyet.Add("Erkek")
spnCinsiyet.Prompt = "Cinsiyet"
When you select a person you should set the selected item in the spinner according to value for the given person.
In in ShowEntry change the code above to:
B4X:
If Cursor1.GetString("Sex")= ("Erkek") Then
    spnCinsiyet.SelectedIndex = 1
Else
    spnCinsiyet.SelectedIndex = 0
End If
 
Upvote 0
Top