Android Question Which method can I use for this kind of Filter?

Itila Tumer

Active Member
Licensed User
Longtime User
I have a table which is person . And I want to filter gradually ,
for example , if I choise firstName on Spinner after that If I click next LastName I don't want to see any other unrelational informations.

Lewis Jhonatan
Lewis Michael
Lewis .....

It should eliminate
Maykıl Jhordan
Jhonatan Brell
..
like that.
I have refernce SQLite2
 

klaus

Expert
Licensed User
Longtime User
If you click in filter the screen on the OR button you'll get AND which is the what you want.
You can either filter with OR or with AND.
With OR, the filter chooses all entries containing at least one of the selected filter intems.
With AND, the filter chooses the entries containing ALL the selected filter intems.
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Referenced SQLite2 again
I want to make this, before look for Filter without using OR button
If I choise JHON i I dont want to see other unrelative LastNames
 

Attachments

  • yanlıs.PNG
    22.3 KB · Views: 187
Last edited:
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Klaus I am trying but it is realy force me. I just treied methods as I understand, I cannot progress . could you help me a bit Klaus, Please
It is quite complicated for me
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I don't know SQLite2, but, if i understood, you have one table only Person (for this job), then you can create on the fly a sql query, on ItemClick events of the Name spinner.

(I will post shortly a snippet about it)
B4X:
Sub spnName_ItemClick(Position As Int, Value As Object)
    Dim MyQuery As String
    MyQuery = "SELECT LastName FROM Person WHERE Name = '" & Value "'"
    FillLastNameSpinner(MyQuery)
End Sub

FillLastNameSpinner should be the routine in which to fill the spinner
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
@Itila Tumer
What did you try and what is complicated ?
You would get more experience if you showed us what you have done and how and we guide you to the solution instead of giving you the whole code for the solution (learning by doing).

@LucaMs
With SQLite2, Itila Tumer is refering to the SQLiteLight2 database example.
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Hi again
I get close my purpose ,but there are some lucks though
Focus on Activity Filter

B4X:
Sub spnLastName_ItemClick (Position As Int, Value As Object)
    Dim i As Int
    Dim Query1 As String
    Dim Curs As Cursor
  
  
    Query1 = "SELECT  LastName FROM persons WHERE FirstName = '" & spnFirstName.SelectedItem & "' "
    Curs = Main.SQL1.ExecQuery(Query1)
    'spnLastName.Add("no filter")
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        spnLastName.Add(Curs.GetString("LastName"))
    Next
    'Curs.Close
End Sub

That is what I did. I also add my files ,

When I click on any of spinner , first time it doesn't seem in spinner.
After I chose "no filter"
I click again the same spinner and how many time that I click in. This exist same .
Hard to explaining, just chose FirstName
and LastName you will see " no filter" ,but YOu chose it, after that you click again , you will see the some changes
after third time click you will see the twice same Last Names.
I hope I coudld intreduce myself clearly :/
can anybody help me ,please
 

Attachments

  • SQLiteLight2.zip
    17.9 KB · Views: 133
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
You want to fill spnLastName when the user chooses a name by spnName,
then you have to put that code (modified) in the event of spnName.
(Many people rightly recommend putting the code in a separate routine, not in the events of views)

B4X:
Sub spnName_ItemClick (Position As Int, Value As Object)
    Dim i As Int
    Dim Query1 As String
    Dim Curs As Cursor
   
    Query1 = "SELECT LastName FROM persons WHERE FirstName = '" & Value & "' "
    Curs = Main.SQL1.ExecQuery(Query1)
    'spnLastName.Add("no filter")
    spnLastName.Clear
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        spnLastName.Add(Curs.GetString("LastName"))
    Next
    Curs.Close
End Sub
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Thank you LucaMs, it solved for unnecesarry routine with spinner.clear
one problem is the same again, I click on second , it keeps previous information, Can you have a look FİLTER part ,LucaMs
something is missing but I can not see it

I tried to modifie the filter activity.
 

Attachments

  • SQLiteLight2-1.zip
    17.9 KB · Views: 138
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Thank you so much Klaus, That is exactly procedure what I want
Thanks a lot

I will manage the spinner City compare to them. Because I realize it needs some repair.
 
Last edited:
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Hello Klaus
I need some help again.
I have been tring some combinations to fix some lucks.
I realize some missing, but I coulnd't find it.
I click FirstName, and I can filter LastName depend on choisen firstname, But
If I want to chose different firstname, last name changes but not reading properly. Please test it.Maybe it does need to see "no filter" on spnLastName.
Depending on it, I have some questions can be solved that way.
Second my thing may come up,after that
Thanks
 
Last edited:
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
If we try first time. It works fine. But after ıf I want to change Fİrstname, LastName change otomaticly,
But I think ıt is not been reading by spinner!! because If I clikc on spinner City , Nothing seen in it. Unless we dont choise any thing in spninerLastName.
Aint I right? :/
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…