I have 3 list views and 3 adapters correspondingly. Then class Menu, that contains ArrayList of Products, where Product is also a class.
1st adapter contains ArrayList and display all menus in ListView1.
2nd must contain and display all Products from Menu, selected in 1st adapter.
3rd must contain all available products, that are not in 2nd ListView.
The question is, how organize architecture in such way, that selecting one item from first ListView affect 2nd and 3rd Adapters. I mean do I need to create a new class, that will hold all changes, or it is better to make ArrayLists static and call their updates from OnClickListeners?
I would think that the 2nd and 3rd views wouldn't even be displayed until a selection was made on 1st view, no?
Regardless, if 2 and 3 are exclusionary drawing from the same list of products, it sounds like you should be able to build them using the same underlying data source. How are you populating these adapters? A content provider sounds like it would suite this well if you have a large enough product list.
In terms of behaviour, when a selection is made on the 1st view, that should cause a refresh of your 2nd and 3rd views on the newly changed parameters. So if in the 1st view the user has selected a number of menus which contain products, the 2nd view should do a query of some kind using the selected menus as a key for which products to then display. The 3rd view would just be what's left over, or use the selected menu as sort of a reserve key, i.e. only get products not in said menus, which would be a minor change to the query.
Related
I'm a beginner android developer. I am creating an app but having trouble to get a rough outline for my next task which I am going to explain below. I am not asking for code. I just want to know the best way to do the below.
I have an Activity that displays a RecyclerView with a list of items like this:
My question is related to the 3 checkboxes.
How should I approach creating the layout in the pic? Do I have to include 3 checkboxes and 3 booleans in my main object class? The other items in the object class are saved in SQL database and the RecyclerView in the activity gets its data from there using a cursor. Can the value of the checkboxes be retrieved using the cursor?
Do I create a separate sparseBooleanArray for the checkboxes? Do I create a HashMap for them?
Should I store the value of the checkboxes (Checked/Not Checked) in SQL or SharedPreferences?
This is basically an opinion based question and hence I am throwing some suggestions on how you should implement it. If I have understood your problem correctly, you have provided a single list item in your RecyclerView and the items are being populated from a local sqlite database table.
Hence there are three checkboxes for each of the list item and yes, of course you need to save the states of the checkboxes in your sqlite table along with the information of the list item. I do not know about your current table structure. However, the pseudo implementation of your updated table structure may look something like the following.
item_id description checked_status
----------------------------------------
1 Some desc null (Not checked)
2 Some desc LOCK
3 Some desc DONE
4 Some desc NOTIFY_ME
Hence when you are clicking on your checkbox, you need to update the sqlite table accordingly with the newly updated data for that specific row and update the RecyclerView items accordingly.
I am trying to filter a list that is placed into a listview through the use of 2 drop down boxes.
The first dropdown box is titled price and the second is owner.
I want to be able to select a value in one or more of these drop down boxes and then have the List view re-render with the filtered results.
The trouble is I do not know how to begin this task, would someone be so kind as to enlighten me :D
Thanks in advance!
Your best starting point is probably this example: (Source code also available on this page, ChoicePage.java is the name)
First of all, you have to use a dynamic model in your ListView that generates the list of items depending on what you had selected in the dropdown boxes.
Then the basic idea is that you add an AjaxFormComponentUpdatingBehavior to the components that control the updates (your two dropdown boxes in your case), and in the onUpdate() method of this behaviour you should add the component you want to update to that AjaxRequestTarget passed.
I have to design an application which handles customer orders. The GUI has tabs, one for the customer and one for the admin. In the customer tab, he has the possibility of submitting an order, by chosing the products from the product list, each having a checkbox in front of them and a text field in which the quantity will be specified.
I am using the netbeans gui editor for the design and I am a bit stuck as the code cannot be modified. I cannot create the product list dynamically (so to create a line for each product in the product array list, and on each line to put the checkbox and the textfield) or at least I don't know how to.
My question is - is there any way of dynamically creating such a list (checkbox + label with the product name + textfield which waits for the quantity) or is there an alternative to my idea ?
Sounds like you need to use a JTable for your list of Products and Quantities. In the NetBeans GUI editor you will only be able to place the JTable on the panel you are designing. After that you need to define a 'Model' for your table which will hold the data you are entering. See the official Oracle Java tutorial on How to Use Tables.
Of course there are lots of other use cases that would fit your requirements, but your design sounds fine. The checkbox is probably superfluous though, as entering a quantity against a product should be enough to indicate that the customer has chosen that Product. If your list of Products gets too long, though, you might want to re-visit this design. Perhaps the table could have 2 coulmns, the first one being a combo-box list of Products, and the second column has the quantity.
In my application, I have URN-identified data coming in from the server. I'm in the process of abstracting as far as possible so there is very little to no logical code in my views, and I'm using a generic presenter that wraps those views. All widgets have URNs, making it super easy to map incoming data to a specific widget (until now, a 1 to 1 relationship). This has worked well for pretty much every widget, and now I've reached a point where I'm tripped up.
Assume I have (just for simplicity's sake) two RadioButton elements on a view. These buttons belong to a "group" (just by setting their name values to the same thing), but obviously they're 2 distinct elements. I can't map my URN-identified data to a single widget as in every other case because, in this case, it is two widgets.
Here's an example of what I mean:
Utility Company is a ListBox, so just one widget there. I map each item in the list to a specific Enum value.
Utility Rate is a TextBox, so again just one widget to map.
For Energy Usage, they can select to use either an average for the year or input 12 monthly values. I'm stuck here. I can't map to just one of the RadioButton elements, because then I'd need some extra logic in the view to handle the behavior appropriately.
Am I stuck mapping to just one widget and sticking (unwanted) logic in my view to determine what the state of all of the elements should be based on the value that came in for the one widget that is mapped?
How should I handle this case?
Edit (Solution):
Following the concepts of jusio's answer, I came up with a workable solution. Because I didn't want to go sticking special case handling through my logic to take care of a non-widget, I created a RadioButtonSet faux widget (public class RadioButtonSet <T extends Enum<?> & HasDisplayText> extends Widget implements HasValueChangeHandlers<T>, HasValue<T>), into which I manually pass the radios I intend to group. Having done that, I can get or set its value and have it fire appropriate events when the user changes the selection. Then mapping the collection of radios is no different than doing so for a listbox. Thanks jusio.
I believe in your case you shouldn't treat radio buttons as two separate widgets, basically in your case you can treat the radio button group as combo box, because behavior is almost the same (the only problem is that you have additional master detail). So basically what you will have to do is to wrap real BO objects into some kind of RadioButtonGroupModel, and give it to view, view can take this model and generate radio buttons (with some editors or whatever else). I remember running into this problem when i was extending databinding FW for JFace, and this was the best way I could find to solve this problem.
If I understood correctly the problem, there are 2 possible solutions:
Give each RadioButton a unique URN (ex: oldURN_1 , oldURN_2)
When you send data for a URN, disable the other one
Keep the same Name for each RadioButton but add a number variable in the data the server sends indicating which radioButton it is supposed to use (ex: 0 for Average and 1 for Monthly)
I'm currently making an app for a forum, I want to add a favorites feature where there is a list of different sections of the forums people can add to their favorites list for quick access to them.
I'm having one slight problem though, I'm using a listview for the list of their favorites, so I need to add a new value to the listview when the user adds a new section to their favorites.
So really all I need to know, is how can I add to my string array for my list view, with a button? Or can I have all the options in the array and then decide witch ones show up according to what the user has chosen?
You could send an array of string with the current favourites to the list adapter. When more favourites are added, you can add them to the array and call
list.notfiyDataSetChanged();
This will update the list.
If you have a large enough array to hold all the possible options you can use setVisibleRowCount(int) to change how many are visible based on how many items are currently in the array.