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 5956647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:17:14+00:00 2026-05-22T18:17:14+00:00

Hey, I’m currently having trouble with a small Android application I’m making. What I’m

  • 0

Hey, I’m currently having trouble with a small Android application I’m making. What I’m attempting to build is:

  • A list interface with
    • Each row having two TextViews (a title and a caption).
    • Have the values of these to be drawn from two separate string array resources.

The interface has the following text views in rowLayout.xml,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:orientation="vertical">

<TextView android:text="@+id/rowTitle"
          android:layout_height="wrap_content"
          android:id="@+id/title"
          android:textSize="25px"
          android:layout_width="match_parent">
</TextView>

<TextView android:text="@+id/rowCaption"
          android:layout_height="wrap_content"
          android:id="@+id/caption"
          android:textSize="25px"
          android:layout_width="match_parent">
</TextView>

and the string resources are,

<string-array name="menuEntryTitles">
    <item>Start</item>
    <item>Stop</item>
</string-array>

<string-array name="menuEntryCaptions">
    <item>Starts the update listener service.</item>
    <item>Stops the update listener service.</item>
</string-array>

There should be two rows titled Start and Stop and each has their relevant captions. I’ve attempted using an ArrayAdapter to implement this,

ArrayAdapter listAdapter = ArrayAdapter.createFromResource(this,
             new int[] {R.array.menuEntryTitles, R.array.menuEntryCaptions},
             new int[] {R.id.rowTitle, R.id.rowCaption});

but I’m getting errors due to createFromResource requiring int arguments when I can only provide int[].

Hope someone here can point me in the right direction.

Cheers

  • 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-05-22T18:17:14+00:00Added an answer on May 22, 2026 at 6:17 pm

    One solution is to create your own adapter since ArrayAdapter only uses one array, and not two.

    You can create the adapter as a private class within you ListActivity. Try something like this (warning: code not tested):

    public class MyListActivity extends ListActivity {
        protected void onCreate(){
    
            ....
    
            // Get arrays from resources
            Resources r = getResources();    
            String [] arr1 = r.getStringArray("menuEntryTitles");
            String [] arr1 = r.getStringArray("menuEntryCaptions");
    
            // Create your adapter
            MyAdapter adapter = new MyAdapter(arr1, arr2);
    
            setListAdapter(adapter);
        }
    
        private class MyAdapter extends BaseAdapter {
            private LayoutInflater inflater;
    
            String [] arr1;
            String [] arr2;
    
            public MyAdapter(String[] arr1, String[] arr2){
                inflater = (LayoutInflater)MyListActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
                this.arr1 = arr1;
                this.arr2 = arr2;
            }
    
            @Override
            public int getCount() {
                return arr1.length;
            }
    
            @Override
            public Object getItem(int position) {
                return null;
            }
    
            @Override
            public long getItemId(int position) {
                return 0;
            }
    
            // Used to keep references to your views, optimizes scrolling in list
            private static class ViewHolder {
                 TextView tv1;
                 TextView tv2;
            }
    
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
    
                ViewHolder holder;
                if (convertView == null){
                    convertView = inflater.inflate(R.layout.row_layout, null);
    
                    // Creates a ViewHolder and store references to the two children views
                    // we want to bind data to.
                    holder = new ViewHolder();
                    holder.tv1 = (TextView) convertView.findViewById(R.id.rowTitle);
                    holder.tv2 = (TextView) convertView.findViewById(R.id.rowCaption);
    
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder)convertView.getTag();
                }
    
                holder.tv1.setText(arr1[position]);
                holder.tv2.setText(arr2[position]);
    
                return convertView;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey having some trouble trying to maintain transparency on a png when i create
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey, I've been developing an application in the windows console with Java, and want
Hey, I right now have a list of a struct that I made, I
Hey guys I have about 8 fieldSets and Im iterating over a list. I
Hey guys I'm running this code in Android: public ServiceServer(String serverName) { this.serverName =
Hey all. I'm trying to see about handling events in a console application. I
Hey guys im making a c++ game and im trying to load a bitmap
Hey guys, sorry I'm kind of new to programming, but I had a small
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)

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.