Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare names of every resource with the content of a variable of sqlite database

I hope you can help me, I already researched my case but didn't found a good answer. I want to compare the content of a variable with the names of all existing resources (if possible only with drawable resources).

The question in short: How to compare the String content of an variable with a list of all resource names, preferential only with drawable resources? Or in other words: How to get a list (containing Strings) of all resource names, preferential only drawable resources?

The Case: I want to display a symbol based on a given type. This type is retrieved from a SQLite Database. There are many symbols stored as a drawable resource, they all are named like on of the possible types. For every stored type in the database I want to display the fitting symbol in a list. The equality should be find out through a comparison (via the contains method) between the variable "type" and a list containing the names of all (drawable) resources.

Example: In the database are types named "A", "B" and "C". In the drawable resources folder are graphics with the name "A", "BX" and "S". The comparison should lead to the case, that in the list only type "A" is connected with the fitting drawable symbol "A". Type "B" and "C" have no likely named drawable resources and thus shouldn't display any symbol.

I hope you understood my question and thank you in advanced for your help.

like image 877
Elementary Avatar asked Dec 11 '12 12:12

Elementary


People also ask

How can I compare two SQLite database files?

Basically - in order to compare two SQLite database files, you need to click the "Compare..." button. This will open up the "Comparison Details" dialog in which you'll fill in the paths to both SQLite database files and choose the comparison mode: Compare schema only- For comparing only SQL schema differences.

How do I view the contents of a SQLite file?

Open a command prompt (cmd.exe) and 'cd' to the folder location of the SQL_SAFI. sqlite database file. run the command 'sqlite3' This should open the SQLite shell and present a screen similar to that below.

Does SQLite have variables?

SQLite doesn't support native variable syntax, but you can achieve virtually the same using an in-memory temp table.

What are the 4 main datatypes in sqlite3?

SQLite only has four primitive data types: INTEGER, REAL, TEXT, and BLOB. APIs that return database values as an object will only ever return one of these four types.


2 Answers

Or in other words: How to get a list (containing Strings) of all resource names, preferential only drawable resources?

This is probably what you want:

Field[] fields = R.drawable.class.getFields();
String[] allDrawablesNames = new String[fields.length];
for (int  i =0; i < fields.length; i++) {           
    allDrawablesNames[i] = fields[i].getName();
}
like image 182
user Avatar answered Sep 21 '22 01:09

user


Sorry, I know you were looking for a Java solution, but I did not find any solution for the C# and Xamarin issue in StackOverflow, so I will leave my solution for Android here if you don't mind.

I found a well written class ReflectionUtils in GitHub, just used it and made this method to call.

    private List<string> GetAllStrings()
    {
        IEnumerable<FieldInfo> fields = ReflectionUtils.GetAllFields(typeof(Resource.String));
        List<string> list = new List<string>();
        using (var enumerator = fields.GetEnumerator())
        {
            try
            {
                while (enumerator.MoveNext())
                {
                    list.Add(enumerator.Current.Name);
                }
            } catch (Exception e)
            {
                // Handle exception.
            }
        }
        return list;
    }
like image 28
technik Avatar answered Sep 21 '22 01:09

technik