John
John

Reputation: 197

Array defining in Android Application

I want to use the concept of array in my Android Application, I don't know how to do that actually.

So could anybody please help me how to do that on demand.

Upvotes: 0

Views: 3337

Answers (3)

Macarse
Macarse

Reputation: 93183

I guess you are talking about arrays in Android through the res folder.

Create an array.xml inside the /res/values folder with something like this:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
  <string-array name="names_list">
   <item>John</item>
   <item>Peter</item>
   <item>Charles</item>
  </string-array>
 </resources>

You can get that array on your Activity by doing:

getResources().getStringArray(R.array.names_list);

Upvotes: 4

androidworkz
androidworkz

Reputation: 2942

There are alot of different "array" types in java... there are actual arrays like Thorsten showed you and then there are lists, collections and hashes. Take you pick. :) A great place to start learning more about Java is the docs.

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/

http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/

Upvotes: 1

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56747

This defines an array of 5 strings:

String[] stringArray = new String[5];

However, I can not imagine that this is really what you're talking about...

CLARIFICATION
If you actually don't know what an array is, then my reply will give you a hint. In case you're talking about something else, this reply should indicate that you're not giving enough detail. You might as well be talking about this...

Upvotes: 0

Related Questions