Android Studio varying number of buttons - java

How can I have a varying number of buttons with androidstudio? So lets say there is a list and for each (not null) element in this list a button is shown to a particular user. Other users might add or remove elements in this list, i.e. the number of buttons displayed needs to be able to change over time.
I just ask for a hint to an appropriate libary/approach/... to this (google doesnt give good results for this)... the rest i try to figure myself then.
Any help is apprechiated!

Related

How to iterate over elements of the same type in Android?

I have been working on a (probably bad, but I don't know enough about Android Studio) application for displaying objects from lists that may be on multiple lists (Magic cards that are in multiple decks), and because I'm bad I have a 21 checkbox view to represent each deck. When these are checked, it allows me to sort and filter and what have you, but I cannot figure out how to iterate over all of them without manually writing up a hard-coded array of their IDs.
Each of the checkboxes was created manually. If there is a better way to do this, feel free to answer with that as well/instead.
EDIT: I don't have any example code (aside from knowing that findViewById(R.id.checkBox1) returns the first checkbox), but here is a picture of my current layout. I am using a blank project with no special layouts or anything. All of the checkboxes are independent and the only thing they have in common is that they are on the same page.

Showing a counter dynamically for JList items highlighted

I have a program that I created for work. This program takes an uploaded file, reads it, and puts the data into a JList in the GUI. The GUI actually has two lists and the user is able to move items between the left and right list by highlighting them like usual with a JList and then hitting an arrow to move the items. The lists are multiple-interval selection.
One small addition I would like to add is some type of counter that shows the user how many items they have selected before they actually move them between lists. This would need to be dynamic so if the user holds control down and begins clicking the counter will continue to update the number of highlighted items.
As the lists are often quite large and a user might need to move an odd number of transactions between the lists (Think 300 transactions in left list and the user needs to move exactly 50) it would be beneficial to have this counter.
Can anyone think of how this could be done? I'm not sure how to add an action listener to just clicking on the items. Please also let me know if I need to elaborate any more.
Generally my question is can I create an action listener just for when a user clicks a item in a JList that updates a counter for the current selected indices? Also it would need to change when they no longer have selected an indice.
Register a ListSelectionListener with your JList.
The listener could simply query how many rows are selected and update the number in the panel to that. Perhaps use getSelectedValues().size().
http://docs.oracle.com/javase/8/docs/api/javax/swing/JList.html#addListSelectionListener-javax.swing.event.ListSelectionListener-

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.

How to make add/remove item in list view modify variables (int and double) in Android

I'll keep this short. I am creating an Android program to allow users to create test mech builds outside of a video game in order to determine if their build is possible in game before dropping money.
Currently, a user can click "add modules" to choose between a list of items in a dialog to populate the list view. Each mech is limited to certain variables. Such as weight, slots open, hard points, etc. Once your mech weighs so much for instance, the part cannot be added.
I am looking for a way to populate the list and change variables depending on the part chosen (I'm pretty sure a simple if/else statement will work here) and more importantly I am looking for a way to allow the user to click a list item and remove it from list along with removing the added change to the variables (weight, slots, etc). (example: Part A increases tonnage from 0/100 to 10/100 tons. User removes part A and tonnage drops to 0/100 again).
Thanks in advance!
Visual:
Screenshot I do not have the rep to post images.

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