Android: using a multidimensional string array for a list

On my page / activity in the list of androids I have 2 text fields: the main and the unit are one above the other, but when it comes down to creating an array string for it, I see only examples with one section of text.

<resources> <string name="hello">Hello!</string> </resources> 

To create what I want, I would do an if statement to match the title, and if so, add subtitles, but I would like to have it so that I can read my headers and subtitle lines, as shown below:

  <resources> <string name="hello"> <item>Hello!</item> <item>my subtitle </item> </string> <string name="hello"> <item>Hello!</item> <item>my subtitle </item> </string> </resources> 

But I cannot find an example of how to read this in a list item, etc., so I do not need to do a long if statement in my java to match the subtitles of the header.

Many thanks Si

+4
source share
1 answer

I usually limit the text to the pipe | and split it when displayed. This is a little ugly, but it works.

 <item>item1|item2</item> 

then when i call it in getView (...)

 String[] r = c.getResources().getStringArray(R.array.arraylist).split("\\|"); 

then I define for the index:

 private final int VIEW_HEADING_TITLE = 0; private final int VIEW_HEADING_SUB = 1; 
+3
source

Source: https://habr.com/ru/post/1392495/


All Articles