Android defines a one-dimensional array in the resource file (RES / strings. XML), and indirectly defines a two-dimensional array

We often define strings and one-dimensional arrays in the resource file (RES / strings. XML). What about two-dimensional arrays? The direct definition of two-dimensional array is not found. It can be defined indirectly.

In fact, it's very simple. You can remember it once you've seen it. One dimensional arrays are often used, but two-dimensional arrays should be used less, because you can only define two-dimensional arrays indirectly.

Definition of array:

An array is a set of variable array definitions that define the same data type at one time.

Array features:

Let's first look at how strings are defined. Among them, the method of adding comments: <-- Note content -- >

Of course, it is defined in Java as follows: string a = "Hello world"; Or string s = new string ("abcdefghijklmnopqrstuvwxyz");

1、 One dimensional array

Array method in Java code to obtain resources

By the way, see how to define in Java: String [] s = {"a", "B", "C", "d"};

2、 Two dimensional array

Here, do you know how to define a two-dimensional array? Do you still need to think about it? In fact, you can't define a two-dimensional array directly in the resource file, so you can only obtain a two-dimensional array indirectly, just like a multi-dimensional array.

Parse the above one-dimensional array into two-dimensional array with Java

What is provided here is only one way, so that it can be used when internationalizing multiple languages. Obviously, this is a much slower parsing process. Or use other methods instead of two-dimensional array in design. You may think it's better to define it directly in Java:

Similar to int a [2] [3] = {1,2,3}, {4,5,6};

Here is just a way, not the best, maybe you have better, please leave a message.

Link to this article: http://www.cnblogs.com/liqw/p/4181327.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>