An array of Android resource files (string, int)
Last Update:2015-07-27
Source: Internet
Author: User
<span id="Label3"></p><pre><span style="color: #008080;">1<span style="color: #008000;">/**<span style="color: #008080;">2<span style="color: #008000;">* String array<span style="color: #008080;">3<span style="color: #008000;">*/<span style="color: #008080;">4<span style="color: #0000ff;">Private<span style="color: #000000;">string[] dirstring;<span style="color: #008080;">5<span style="color: #008080;">6<span style="color: #008000;">/**<span style="color: #008080;">7<span style="color: #008000;">* Image Resource ID array<span style="color: #008080;">8<span style="color: #008000;">*/<span style="color: #008080;">9<span style="color: #0000ff;">Private<span style="color: #0000ff;">Int<span style="color: #000000;">[] dirint;<span style="color: #008080;">10<span style="color: #008080;">11<span style="color: #000000;">@Override<span style="color: #008080;">12<span style="color: #0000ff;">Protected<span style="color: #0000ff;">void<span style="color: #000000;">OnCreate (Bundle Savedinstancestate) {<span style="color: #008080;">13<span style="color: #0000ff;">Super<span style="color: #000000;">. onCreate (savedinstancestate);<span style="color: #008080;">Resources res =<span style="color: #000000;">Getresources ();<span style="color: #008080;">Dirstring =<span style="color: #000000;"><span style="color: #000000;"> Res.getstringarray (r.array.dir_string); <span style="color: #008080;">16 <span style="color: #008080;">17 TypedArray Tarr =<span style="color: #000000;"> Res.obtaintypedarray (r.array.dir_image); <span style="color: #008080;">18 <span style="color: #0000ff;">int len =<span style="color: #000000;"> tarr.length (); <span style="color: #008080;">19 dirint = <span style="color: #0000ff;">new <span style="color: #0000ff;">int<span style="color: #000000;">[len]; <span style="color: #008080;">20 <span style="color: #0000ff;">for (<span style="color: #0000ff;">int i = 0; i < Len I ++<span style="color: #008080;" ) {<span>21 dirint[i] = Tarr.getresourceid (i, 0<span style="color: #000000;">); <span style="color: #008080;">22 <span style="color: #000000;">}<span style="color: #008080;">23} </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre><p><p>The array dirstring stores the resource itself (sring type of data), and the array Dirint stores the ID of the RESOURCE.</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #000000;">Textview.settext (dirstring[index]);</span> <span style="color: #008080;">2</span> <span style="color: #008080;">3</span> Imageview.setimageresource (dirint[index]);</pre></pre><p><p>Using the code snippet above, the type of TextView is textview, and the ImageView type is IMAGEVIEW.</p></p><p><p>An array of Android resource files (string, int)</p></p></span>