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

  • Home
  • SEARCH
  • 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 8322115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:16:06+00:00 2026-06-08T23:16:06+00:00

I am working on an application in Android that works with 2 screens. The

  • 0

I am working on an application in Android that works with 2 screens. The firsts creen is simple, it has a TextView initialzed to “Not Set” and a Button. When the user clicks on the button, he/she is taken to the 2nd screen which is one big ListView. The ListView is a list of all highest grossing movies of all time. It would be simple if it were to include just the title, but I need to create the listview such that it has multiple lines. The structure being, the title is oriented left, the gross earnings aligned right and the date released is located on a second row.

The important tidbit is that I need to use string arrays declared at the strings.xml. I have already declared all of them, however my problem is that I am stuck on how to make the Java portion. Here is what I have come up so far.

package com.android.rondrich;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Lab5_082588part2 extends ListActivity {

    public static final String KEY = "KEY";
public static final String RETURN = "RETURN";

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

    String[] titleList = getResources().getStringArray(R.array.title_array);
    String[] grossList = getResources().getStringArray(R.array.gross_array);

    setListAdapter(new ArrayAdapter<String>(this,
            R.layout.lab5_082588part2, grossList)); //not sure if     correct to have 2 setListAdapters

    setListAdapter(new ArrayAdapter<String>(this,
            R.layout.lab5_082588part2, titleList));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

                Intent intent = getIntent();
                String title = ((TextView) view).getText().toString();
                intent.putExtra(Lab5_082588part2.RETURN, title);
                setResult(RESULT_OK, intent);
                finish();

            }
        });
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        finish();
    }

}

Some of the snippets I have researched are using this kind of approach (sample code)

private ArrayList<SearchResults> GetSearchResults(){
 ArrayList<SearchResults> results = new ArrayList<SearchResults>();

 SearchResults sr = new SearchResults();
 sr.setName("Justin Schultz");
 sr.setCityState("San Francisco, CA");
 sr.setPhone("415-555-1234");
 results.add(sr);

However this method will prove very tedious for long lists. The question is that:

How do I incorporate using string arrays declared in strings.xml to have multi-line listview without resorting to hardcoding it like above?

  • 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-08T23:16:09+00:00Added an answer on June 8, 2026 at 11:16 pm

    You can’t set the adapter two times to show the row like you want instead you have to implement a custom adapter(there are thousands of tutorials out there to look at so I’ll leave this part out).

    To extract the data from the strings arrays you would(almost) use the snippet you posted:

    String[] titleList = getResources().getStringArray(R.array.title_array);
    String[] grossList = getResources().getStringArray(R.array.gross_array);
    // ...
    
    private ArrayList<SearchResults> GetSearchResults(){
        ArrayList<SearchResults> results = new ArrayList<SearchResults>();
        // make sure the arrays have the same length
        for (int i = 0; i < titleList.length; i++) {
            SearchResults sr = new SearchResults();
            sr.setTitle(titleList[i]);
            sr.setGross(grossList[i]);
            results.add(sr);
       }
       return results;
    }
    

    Then you would use the list returned by this method to fill your custom adapter.

    A layout example:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="title" />
    
        <TextView
            android:id="@+id/gross"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/title"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="Gross" />
    
        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/title"
            android:text="Date" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new in android and currently working on small application that works on
I am working on an Android Honeycomb (v3.0) application that has a requirement of
I am working on an Android application that needs to determine the current tee
I am working on an Android application that shows a map with the user's
i am working to make a Android application that can upload and download data
Hi i am working on web service application in android.i need a class that
I'm working on an Android application that needs to download an image and display
I'm new to Android development and working on an Android application that requires the
I'm working on an application that will be available for Android and iPhone. The
I'm creating an Android application (Android 2.3.3) that has a header, a footer and

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.