Best way to take an input from a list? - java

I'm relatively new in the world of android, and I'm trying to make an application to manage some business trips.
Each trip is made to a city, i was wandering, what is the best way to write down the city? Right now i have an edit text where the user can write the city, there must be some better way, any hints?

You can make EditText and "+" button next to it. Typed city can go to the list after taping "+". You can use RecyclerView for list for example. You can see this in adding bookmarks in Podcast Go app.

Assuming you need to map that city to an existing one, it is a better idea to use something that is more controlled and not free as an EditText.
Spinner or a Popup with list selection could be a good option for that. To make sure that the user chooses a valid city.

Related

android best practice to store non-displayed information in views

I have a listView where each line represents part of the information of a row of a database. With onItemClick the user can select an item in the list and a new activity will start.
id first_name last_name address ....
__________________________________________________
1 Peter Griffin Rhode Island ....
When switching to the new activity I would like to pass on the id in a bundle so that I can easily identify in the next activity what item was clicked.
I am just wondering what the best way is to link the id to the item in the listView which only displays the name. I can come up with various ways, but they all give me the feeling that there should be some better way to do it.
1.) view.setTag()
I don't understand what the intention behind that tagging is. Tagging each view with the id would solve my problem, but it seems very opaque
2.) manual layout with 'invisible' field
I could make the child views manual and add a second field with 0 width that could contain the id. Seems very hacky, though
3.) When populating the array that contains the rows for the listView, simultaneously populate another array with the ids in the same order so that the position variable in the onItemClick method would get me the id as well. Seems like a better way then the above, but I still don't feel it's the best way.
I know, best practice is a subjective concept and there may be no clear answer, but any pros and cons would be appreciated to help me get a better idea of how to do things in a good way.

Dynamic amount of entries in GUI using java

I'm working on creating a basic user interface and I wanted to try and create a portion that is in a scrollTaskPane and is capable of holding multiple entries. As I'm going about creating it I can obviously test it with a simple amount of entries but I'm confused how I can go about later allowing for it to take input to create entries in the scrollTaskPane of maybe 1 entry one time, and then later needing to allow for input of 20 entries. I only know how to use absolute positioning and am trying to figure out the best way to go about it. I also need to later be able to select each entry.
For the entries that will eventually be called and displayed in my interface, I'm planning to store them in a simple text file and use a semicolon as a delimiter between the task "Type" "Name" "Description"(which will be accessible through a button) and "Due Date". Or I may try to learn to use a database for the information. But I haven't decided yet and don't know anything about connecting a database with a java program.
This is the current look (the scrollTaskPane in the middle). And my goal is to put in entries that are each rectangle boxes going across the scrollTaskPane with a checkbox on the end of them. Should I use some sort of grid layout? Or something else? I'm a beginner at user interfaces, so any help is appreciated!
You can make a custom layout, and then keep adding those layout. So extend a layout class, add TextField and a check box in the layout. Initialize the layout with your values, add then add to the ScrollTaskPane.

Creating a flash card set in Javafx

I am trying to create a program in Javafx + Scenebuilder that has a tab pane for creating/loading a card set and another tab for quizzing yourself using that card set, I want to know how to take input from the user in a series of TextFields for a Title to the flash card set and tie that to the flashcard's Question & Answer(entered in TextFields). The user can then enter the flashcard's Title and hit a load button and then go to the other tab and be quizzed with that flashcard set. I also need to know how to store the set so that it doesn't have to be entered every time the program opens.
I had researched on my own for some way to do this but couldn't find a good way to do this, that is why I asked for help.
A HashMap is what I need, after asking someone that actually would give a straightforward answer this is what I was told.

Best way to show results with a list of options

I am trying to make a "Oregon Trail" like game with JAVA for my Computer Science class. It's all going well so far, but I would like some suggestions on ways of doing the following:
The words at the bottom "Health", "Stats", etc are buttons. I was wondering what the best way of making those buttons present information would be. Is there a way I could show them in that information in one of the bottom squares, and when a different button is clicked change the info to that one? Or would it be best to have popup frames to display the information?
IMHO, I'd go with display the content or info of the button in the panels above.
It keeps the information together in a single place and generally makes it easier to manage, no disappearing windows behind other windows for example.
You have any number of options depending on the information you want to display. You could simply use a none editable JTextArea if the information is just text, or a JList if you want to list items if the data is more structured, a JTable and even a JTree if you want to group the data into some kind of groupable hierarchy.
You could use combinations of each, based on your needs

Best way to implement a selection box from a large number of entries

I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array

Categories