0

$

<string name="app_name">demoMark</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="spinner_header">Group Mate</string>
<string-array name="demo_name">
    <item>Product Amount</item>
    <item>1</item>
    <item>2</item>
    <item>3</item>
</string-array>

$

ArrayAdapter<CharSequence> adapteradapter = ArrayAdapter.createFromResource(this, R.array.demo_name, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); itemAmount.setAdapter(adapter);

here is the screenshot with arrayadapter here is the screenshot

Is there anyway that i can implement a loop in the string array in the String.XML ? it will be so helpful if anyone help me out with this.

8
  • You're going to need to use an Array Adapter like stackoverflow.com/questions/5394746/… Commented Jun 3, 2015 at 14:48
  • I already added the array adapter . I added another screenshot of that can you tell me what should I do now ? Commented Jun 3, 2015 at 14:54
  • can you add your actual code to this post? Commented Jun 3, 2015 at 15:04
  • I did now you can check that Commented Jun 3, 2015 at 15:10
  • i don't understand your question Commented Jun 3, 2015 at 15:19

2 Answers 2

1

You can't do a loop in xml directly. Use an external script to generate your xml is an alternative way to do what you need...

Sign up to request clarification or add additional context in comments.

5 Comments

Can you tell me more about the external script ??
Just code a python/bash/whatever script you will run to create your strings.xml
Actually I am using JAVA . I am not an python user. it will be so helpful if it was in java :(
0

As far as I know, it's unable to do that as it does not support xsd. You can read related discussion at here.

To parse XML in your way, I recommend Simple library to process xml data. This library reads XML data and creates into objects (so called deserialization) for you.

The tutorial at above link will give you enough examples, but you might need to do many trial-and-error in order to reflects xml structure to object hierarchy.

2 Comments

is there any other way i can do it without library ?
@MuhtadiAkif // XmlPullParser is default android XML library but it is too naive to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.