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

前端 未结 2 530
谎友^
谎友^ 2020-12-17 01:42

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 (i

相关标签:
2条回答
  • 2020-12-17 02:29

    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;
        }
    
    0 讨论(0)
  • 2020-12-17 02:35

    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();
    }
    
    0 讨论(0)
提交回复
热议问题