Tuesday, March 16, 2010

Re: [Java] Static Array Help in Eclipse/Android

 

The default way to print an array is
String [] array;
System.out.println(array);
For an array of Strings, this will print out
["a","b",...]
If thi is unacceptable, it's better to loop through:
for (int i = 0; i < array.length; i++) {
// Do something with array[i]
}

-----Original Message-----

From: soren.j.winslow@cummins.com
Subj: [Java] Static Array Help in Eclipse/Android
Date: Tue Mar 16, 2010 4:08 pm
Size: 12K
To: Java_Official@yahoogroups.com

I am just starting to work on building Android apps. I have some basic
knowledge of programming, but have never done any Java based stuff. I
apologize in advance for my questions being remedial. Most of what I do is
web based using ASP (vbscript) or PHP, plus I do some VBA.

I am just trying to figure out how to display a static array.

I have an arrays.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="history">
<item>Some text<item>
<item>more text<item>
<item>even more text<item>
</string-array>
</resources>

In my main.xml file I have:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="@id/history" android:layout_height="wrap_content"
android:layout_width="fill_parent"/>

I know that I need to decare my array. The code that I found to do this
is:
String[] history = getResources().getStringArray(R.array.history);

What I dont know is where in my main java file I put it. Currently my main
java file (TriumphHistory.java) looks like this:
package com.TriumphHistory.Soren;

import android.app.Activity;
import android.os.Bundle;

public class TriumphHistory extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Thanks for your help,
Soren

[Non-text portions of this message have been removed]






__._,_.___
Recent Activity:
Visit http://aiaiai.com or http://jgame.org for more groups to join.
Java Official Group is created for the following topics: Java 2 Enterprise Edition - J2EE, Java 2 Standard Edition - J2SE, Java 2 Micro Edition - J2ME, XML, XSL, XSD, XPATH, Web Services, Jini, JXTA for all type of Java Geeks.
Whoever posts spam / ads / job related message will be BANNED IMMEDIATELY
.

__,_._,___

No comments:

Post a Comment