How to Manage SQLite Database For Below Case - android

I got one task as below
Above graph contains different cases which can be occur with the combination of two different selection.
In my application i need to put two drop-down boxes (I.E two spinners), from that two spinners user will select different values and i need to show that value as a result.
Now result after selecting two different spinners value is calculated like this , for example suppose from first spinner I am selecting Benazepril from row number 3 and Amiloride hydrochloride from row number 1, so this selection will give me result as a red symbol mention on graph, which has been marked with black cricle.
Now my question is i need to manage this entire thing on my SQLite Databse, Above description is just a graphical representation of logic, now i need to apply this logic at run time. I need to store all values And It's Combination result on my database. How to handle such situation?
Now Second query is after Selecting any case i need to show small graphical respresentation on my application for two different selection as below
So this is my query, I am not getting how to handle such situation, can any one give some nice guide for it?
Thanks

You could use a table like
create table interactions (
substance1 ..
substance2 ..
interaction ..
)
where you store all combinations and can answer your first question
An alternative approach would be using bitmaps for every row and every type of interaction.Then you have to build your query bitmap according. Every bit stands for a crossing of substance1 with substance2. You have to define the position of substance2 at an other place or table.
create table interactions (
substance
bitmap
interactiontype
....
Instead of the bitmap a string would do it too, where you use different chars for any possible interaction type at the crosspoint like "0X00X000000100".
create table interactions (
substance ..
crossreactions varchar(
)

Related

Flutter advanced datatable how to make diferent last row

I am currently making a custom data table using advanced datatable package. Now managed to make it looked good, following the design I was given except one, how to make the last row different than the rest, fixed one where even if the user navigate to next page of table, the last row will still be there. Pretty much like this.
(sorry for the squared censors...)
I am trying to make the last row look like the "Total" row, so to make something like this in advanced data table? Or any other suggestion for a better paginated data table package?

Dilema: The best way to make table column not sorted

I am creating android app using Kotlin. I have fully functional multi column sorting. When I click on table header column it adds it index to sorting column list. It sorts both ways (ascending and descending). On click it changes direction. Everything works fine. But I would like to know what would be the best solution to remove sorting from one column.
I have few ideas but they don't sound good:
On third column click remove sorting on that column.
Add button which is visible when column is sorted. Button on click removes column from sorted list.
I would like some help because I don't know how to implement this feature in a good way.
Edit1:
Forgot to mention that sorting happens in back-end. In android I just set parameters which columns I need to sort and then send GET request to the server. As response I get sorted data.
I would mimic the way Google Spreadsheets does:
It shows a dialog and you can add sort columns and delete them.
You can see it by selecting some columns and going to Data / Sort the range.
Another possibility would be to have a 3 states switch in each column (sort ascending, sort descending, not sort). Here you can see it working in a website (look at the Multiple column sorting example): http://demos.shieldui.com/web/grid-general/sorting but, in my opinion, it is more confusing.
Hope this helps.

Create multiple instances of an existing listview class dynamically in Android

I'm developing a vocab building app that stores data into an SQLite database. I have a category for different types of vocabulary, for example, a category for GMAT. Each of this category is an activity and has its own table where I store a list of default vocab. The classes for these categories all extend an abstract class full of methods for the menu option items, such as search, add, and delete vocab functionalities.
Now I have 4 categories which mean I have 4 tables in my SQLite database and an activity for each of the categories. However, I want to allow the user to be able to add new categories as they click on a button. The newly added category will be identical to the 4 categories I have already created. So any newly added category will have the same layout, menu items, and functionalities.
I have thought of one solution which is to create these categories first but make it invisible to the users and only show them to the user when the user performs an action to add new categories. In this case, I'll create the activities and tables in advance and just hide them in the beginning. However, with this solution, there will be a limit to the number of categories that the user can add, which is ok but not optimal. It also will cause me to create a lot of potentially unused activities which seems very inefficient.
I have come across posts like this and this, but it doesn't address my problem.
If I'm not clear with articulating my problem, it is like the music Spotify software, where I don't know how to allow the user to add new playlists dynamically.
Thank you so much for your help in advance!
Update: with juergen's suggestion, I can redesign my database to just have one table. So I no longer need to create tables dynamically, but I still have to find a way to create multiple instances of an activity dynamically.
After I redesigned my database according to Juergen's suggestion. I was able to get around this problem by opening a generic activity and alter it based on the extra I put in my intent. So in essence, there's just a single activity pulling and displaying data based on what the extra being passed to it is.

How can I delete an item in a hashtable and have the keys adjust accordingly?

Currently I have a homescreen where the user stores titles of their classes they're taking this semester, and tied to each class is their assignments and flashCards for those classes. When the user long-clicks on one of the items on the homepage, I want to delete the class and all its contents (this includes all flashCards and assignments).
I've stupidly stored my data in hashtables with the keys as integers unfortunately. This has caused some problems when I delete items from the table. The keys are directly correlated to the position on the homescreen, and I can't seem to figure out how to readjust the hashtable when the user deletes something from it.
I've thought about using other data structures such as a arrayList but the problem is that the user could possibly and very likely have only one set of flash cards or only one assignment and it happens to be in the 4th position on the homescreen. This means that I would have to fill the first 3 positions with null first before I could insert the value at the 4th position. I definitely don't think I want that...
Any ideas?
I am afraid that with your current implementation, you will not be able to readjust the numbers in the HashTable. I would suggest you use LinkedList for the items on your screen and store iterators to the elements in that list in the HashTable. This way you will be able to efficiently delete any item.
Just assign unique IDs to all entities such as classes, users and assignments. Use these unique IDs, which may be integers, as keys and in all other places where you need to refer to entities. Do not use sequential order of entity as identifier, because it may change when item is deleted or even when items are reordered.

Calling a custom dialog from a database?

Following on from this question:
ideal database field for calling data to
I have realised that I might be able to simplify my need for information to be brought to the screen by using a Dialog or a Custom Dialog, and by one of these methods I may call the whole finished page from a database instead of using static strings into the layout filling in specific fields with data like I am currently.
There could be a few hundred items or pieces of data to be called up in my App So am I correct with this assumption or do I need a specific other method to acheive this?
I am looking to call a custom dailog from a database so I can call a whole page of information complete but am unsure of limitations on this data wise or even if my sqlite database manager is even good enough for this task, each page will be called up "complete" where as before I was trying to have a template with the unchanging data (coke pepsi etc.)already included and appearing on every "result" page and then blank fields populated with data retrieved from a sqlite database (Litres size etc...) I am unsure which path to take : either make the page complete including all data like an image Or do I stick with my original plan to have a template screen with unchanging fields already in place and the changing information to be populated as needed from a Sqlite Database? hope this makes sense sorry if I was too vague with my question originally Im still learning.
Your question is vague but I'll risk an answer:
If you want to make a dialog like the image you posted on your previous question then this is the way to do it:
Create a custom dialog that will have as content a LinearLayout(with 3 TextViews representing the header labels in your image: COMPONENT, TYPE and AMOUNT, this will be somewhat identical to the list row layout below) + a ListView where the actual data will be shown.
Create a layout file for your ListView row to use(like the LinearLayout above will contain 3 TextViews for the drink name, type number and amount number).
When the dialog needs to be shown just get from the database all the drinks names, types and amounts and bind it to the ListView with one of the adapters based on a Cursor(like a SimpleCursorAdapter)
Getting the values from the database and binding them to many TextViews is not recommended(If you have many(I saw few hundred items or pieces of data)), also your dialog could be called a lot of times by the user in a short period of time and you don't want to do this binding each time for many views.
either make the page complete including all data like an image
Please don't do this!

Categories

Resources