I’m newbie in android developing so I’d like to ask for advice about solving the next problem.
I have 2 SQlite tables: cards and meanings. Each card has one or several meanings. My android application should show a list of the cards with the realted meanings.
I should realise next operations:
- add a new card with a meaning
- add a meaning for an existing card
- read card with meanings, update, delete
As far as I understand best way of realisation this is to make 2 content providers for the cards and for the meanings. Then I’d like to construct a class which would encapsulate cards’ functionality and the put the cards into some kind of adapter. And then bind the adapter to some kind of list view.
I’m not sure that this way is the most optimal, that’s why any advices about better ways of doing this is highly appreciated.
Since a card can have more one or more meanings, then you should use a third table, let’s call it CardMeanings, which has two columns. The unique ID of a card, and the unique ID of a meaning. Each row of this table represents a unique combination of one card and one meaning.
Then use a single adapter to manage this table with a logical view of the relationship and low level methods, available only to the adapter, to maintain integrity. For example, if you delete a card, what should happen? Normally, you would delete the card and all rows in the CardMeanings table with the given card ID but let a single adapter do that and manage all three tables.
The key thing is that the whole point of the adapter is to turn a physical view (3 tables) into a logical view (cards and their meanings). Your activity code should only deal with the logical view and your adapter should be the only thing to deal with the physical view.