0

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.

5
  • 1
    Absolutely don't do that!! The table design has to be fix, no matter what data the user inserts. Change your design. For instance there is one table containing the categories - all categories. Commented May 20, 2016 at 1:07
  • Thanks for your reply! Ok, I can redesign my database so there is only one table with an extra column specifying what type of table it is. However, with this change, how can I address the problem specified in my post/problem? Thanks again! Commented May 20, 2016 at 1:20
  • use one activity with your ListView and the Spinner holding all the categories Commented May 20, 2016 at 2:00
  • Hello pskink, sorry but can you elaborate on that? I'm not sure how that addresses my problem. I probably didn't articulate my problem well enough. Thanks! Commented May 20, 2016 at 2:44
  • 1
    setupt the Spinner with a SimpleCursorAdapter passing a Cursor that holds all the categories you have in your table, after selecting any category update the words for your ListView (also using SimpleCursorAdapter) Commented May 20, 2016 at 2:52

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.