Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:32:51+00:00 2026-06-13T00:32:51+00:00

I created an app which displays a list of fruit and when selected the

  • 0

I created an app which displays a list of fruit and when selected the new activity display the image and the name of the fruit. However I need to localize the app and my strings are stored in a string array in Java as opposed to in the strings.xml Values folder.

Is there a simple a way to read in xml strings into the array and will it work if local settings are switched to french. (values-fr).

package com.example.favouritefruit;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class FavouriteFruit extends ListActivity 
{
    //string array containing types of fruit
      static final String[] FRUIT = new String[]
            {
                "Apple", "Orange", "Banana"
            };

      static final String SELECTEDFRUIT = "com.example.favouritefruit.SELECTEDFRUIT";

      @Override//onCreate Method
        public void onCreate(Bundle savedInstanceState) 
            {
            super.onCreate(savedInstanceState);

            /*Use a java layout as opposed to an xml layout.
            setListAdapter takes a list adapter or an array adapter
            Creates a new class ArrayAdapter Class*/
            setListAdapter(new ListArrayAdapter(this, FRUIT));
            }

        //Creates an intent to move to a new activity

      public void onListItemClick(ListView l, View v, int position, long id)
      {
          super.onListItemClick(l, v, position, id);


        try {
            Class test = Class.forName("com.example.favouritefruit.AppleActivity");
            Intent intent = new Intent(FavouriteFruit.this, test);

            TextView textView = (TextView) v.findViewById(R.id.label);
            String fruit = textView.getText().toString();
            ImageView fruitImage = (ImageView)v.findViewById(R.id.logo);

            //intent.putExtra("IMAGE",""+);
            intent.putExtra(SELECTEDFRUIT,fruit);
            startActivity(intent);
            }   catch (ClassNotFoundException e) {
            e.printStackTrace();}

      }

}

class ListArrayAdapter extends ArrayAdapter<String> 
{
        //Context allows the retrieval of resources such as layout
        private final Context context;
        private final String[] fruit;

        //create the ArrayAdpater
        public ListArrayAdapter(Context context, String[] fruit) 
        {
        super(context, R.layout.activity_favourite_fruit, fruit);
        this.context = context;
        this.fruit = fruit;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) 
        {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //inflater  dynamically loads the layouts
        View rowView = inflater.inflate(R.layout.activity_favourite_fruit, parent, false);
        //get the textView
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        //get the ImageView
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        //set the text to the string values based on position
        textView.setText(fruit[position]);

        // Change item based on its position in the string array
        String fruitPosition = fruit[position];

        System.out.println(fruitPosition); 
        //assign the image to to the relevant fruit
        if (fruitPosition.equals("Apple"))
            {
            imageView.setImageResource(R.drawable.image_apple);
            } 
        else if (fruitPosition.equals("Orange")) 
            {
            imageView.setImageResource(R.drawable.image_apple);
            } 
        else if (fruitPosition.equals("Banana"))
            {
            imageView.setImageResource(R.drawable.image_apple);
            }

        //return the layout
        return rowView;
        }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:32:52+00:00Added an answer on June 13, 2026 at 12:32 am

    To get an an xml String array from resouces, use:

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

    Yes, if you have localized versions of the resource, it will automatically load the appropriate one based on the user’s device settings. You can make localized xml resources of the individual strings, and use a single string array resource that references the string resources by id/name

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I need to get a value from an AlertDialog which displays
I have created a listview which displays the installed applications. It has app icon
I have created an app in which I had use SPenSDK to create image
In my app I have created a List of items which are displayed on
I created an App which uses Timer class to callback a method at a
I've created an app which contains form and that have to filled up in
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I created an app in which a file is created. The file directory I
I have created an app in which I have used achartengine to construct the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.