Question

I'm fairly new to android programming and have a couple years of university experience in Java. I am planning on writing an app for android that will require me to see what category an item entered belongs.

As an example, if a user inputs 'apple', that data must be placed under a 'fruit' category. So in other words I require a data file that will be able to tell me what category the item is in or alternatively the user can add an item to a category if it is not yet categorised.

I am wondering what would be the best way to store this data. Should I use an xml file, database file, text file or what? It would be necessary to perform look-ups and also insertions.

Thanks in advance

Was it helpful?

Solution

I think this question is more of a personal preference, but I would use XML in this case. You can have the structure predefined with distribution of your app, and modify/write the file at runtime. Its easy to read and understand, and just as easily modified. Simply universal. Sqlite has its positives in large forms of data, but can be much more complex for something that doesn't need much detail.

<index>
    <category name="fruit">
        <item>apple</item>
        ..... 
    </category>
    ...... 
</index>

A simple for loop through the categories, and see if the item is present, else add it.

Hope this helps, happy coding!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top