Some sort of Autocompleteview?

AscySoft

Active Member
Licensed User
Longtime User
I just finish a desktop application who export/import into an sqlite database some usefull informations. Now the tricky part is to somehow manage to display into a listview/spinner or something some information from that database.

More exactly, the question is: what is the best approach to display a huge items/products list/predefined customers into b4a application?
The records in database table are many, usually over 500, 600 records, even more. The user is suppose to pick an item from this list then carry on...etc. To scroll this list only is out of a question... maybe some autocomplet view/something will help. Or maybe a combination of textview/ listview, I don't know.

PS: (maybe this link will explain better than me: Auto Complete | Android Developers)
Thanks.
 

moster67

Expert
Licensed User
Longtime User
I don't know what kind of data you are presening users with but if the records are ordered according to the alphabet, you could use the tab-view where each tabs show a range of letters.

tab1: from A to D
tab2: from E to H
etc..

just an idea..
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
I've just think of something.
What if I create 3 views, a textview, a button and a listview
When user insert 2-3 characters into textview and press the button, then a specific SQL command filling the listview is executing.

This I think is the best approach. But the question still remains: are there any other ideas? More ideas, the better
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
May be Another Option

I've just think of something.
What if I create 3 views, a textview, a button and a listview
When user insert 2-3 characters into textview and press the button, then a specific SQL command filling the listview is executing.

This I think is the best approach. But the question still remains: are there any other ideas? More ideas, the better

Hello,

You might look at using a ListView and this: ListView1.FastScrollEnabled = true. This works great for long list and is really nice. I use it in one of my apps and I have over 1,500 items! You can get to the item you want very fast! Look at this info here:

http://www.b4x.com/forum/basic4android-getting-started-tutorials/6537-listview-tutorial.html#post38231

Thanks,

margret
 
Last edited:
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
Hello,

You might look at using a ListView and this: ListView1.FastScrollEnabled = true. This works great for long list and is really nice. I use it in one of my apps and I have over 1,500 items! You can get to the item you want very fast! Look at this info here:

Yes, Margret, thank you, I was aware of that option, however I am still searching for something like autocomplete, that's because I'me afraid that the users (are some) could do many mistakes. And mistakes are not an option in this line of field (bussines application/many clients >5000, many items to sell, easy to make mistakes)
But is good to know that in practice this option is a good one.
I will try it, definatly.
Are there any other options?
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
EditBox & ListView

Yes, Margret, thank you, I was aware of that option, however I am still searching for something like autocomplete, that's because I'me afraid that the users (are some) could do many mistakes. And mistakes are not an option in this line of field (bussines application/many clients >5000, many items to sell, easy to make mistakes)
But is good to know that in practice this option is a good one.
I will try it, definatly.
Are there any other options?

You could have an EditBox and in the TextChanged event you could call a sub to populate the ListView. It would be filtered on the Edit text. The more they type the smaller the list will get. If the Edit text is empty "" then don't load anything in the ListView. This way you don't need the button, just call the sub off the TextChanged event. If you don't want the listview changing for every letter they enter, use the EnterPressed event.

Thanks,

Margret
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
How about having an edittext box, and run a SQL query in the textchanged event. Feed the result into a list view, that way as you type in a word, the selection will be narrowed down until you can see the one you want.

Hope that makes sense.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
How about having an edittext box, and run a SQL query in the textchanged event. Feed the result into a list view, that way as you type in a word, the selection will be narrowed down until you can see the one you want.

Hope that makes sense.
This makes a lot of sense. However it is better to start a timer which will make the query in 100ms. This way the user will be able to enter (or delete) several characters and only then the query will be done. Otherwise it may be annoying for the user.

You can see this behavior in the IDE in the libraries tab. When you select or unselect a library it shows a loading message. The IDE is not really busy doing anything at that moment. It just ways a few moments to allow the user to select or unselect more libraries without loading the whole information again and again (each selection requires loading all selected libraries information).
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
You could have an EditBox and in the TextChanged event you could call a sub to populate the ListView.
Margret

How about having an edittext box, and run a SQL query in the textchanged event. Feed the result into a list view, that way as you type in a word, the selection will be narrowed down until you can see the one you want.

@Margret and Kickaha - you're both right. I was only afraid of only one thing, the thing that Erel was kind to enlighten us...

This makes a lot of sense. However it is better to start a timer which will make the query in 100ms. This way the user will be able to enter (or delete) several characters and only then the query will be done. Otherwise it may be annoying for the user.

Now, in this case I really don't need the button, becouse of the timer. Smart move.
Now this is I was looking for :sign0060:.
Thank you all.
:sign0188:

Too bad that virtual keybord will block a large portion of the screen. Maybe in the future a native AutocompleteTextView will be available in B4A and some sort of keybord manipulation, (a sendkeys for BACK or somthing). Well, let me dream nicely at least.

PS: if I'll have the time I will inform you about my progress with the project.
 
Last edited:
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
Just an update

In case someone is wondering how things worked in real life situation, I manipulate a database with over 500 records, and the Erel's suggested way was good, also Margret's idea worked OK.
I just set a filter for over 2 characters in textview(filter), and remembered last search not to do it again, and the time tick was set to 1500 ms...
Even without a timer, the search after every change was almost instantly.

So good job people, nice to find B4A!
 
Last edited:
Upvote 0

lagore

Active Member
Licensed User
Longtime User
I have been working on a similar problem this is the basic code to get an autocomplete from an sql field
B4X:
Sub edittext1_TextChanged (Old As String, New As String)

   ListView1.SingleLineLayout.ItemHeight = 28dip
   ListView1.Clear               
   Cursor = SQL1.ExecQuery("SELECT * FROM AutoWords WHERE words like '" & EditText1.text & "%'")
      
      If Cursor.RowCount > 0 Then
      For i = 0 To Cursor.RowCount - 1
         Cursor.Position = i
         ListView1.AddSingleLine(Cursor.GetString("words"))
      Next

      End If
End Sub
In the code above the SQL table is 'AutoWords' and the field is 'words' it works very quickly. The SQL is Initialize else where in the program, you could also put in a check for 'EditText1' length and not begin the routine until you have a minimum number of letters and also put in a timer as suggested by Erel. The biggest problem is trying to find somewhere on the screen to put the listview so that the keyboard is not covering it up.
Edward
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
The biggest problem is trying to find somewhere on the screen to put the listview so that the keyboard is not covering it up.
Edward

Not necessary... just
B4X:
dim p as phone
(sub globals) (add also a referince to phone librarry on Libs tab in IDE

and when U click on listview1 (i ex.) or EditText1.enter_Pressed...do something like this
B4X:
 p.HideKeyboard(Activity)

That should do it!
 
Upvote 0
Top