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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:58:42+00:00 2026-06-03T00:58:42+00:00

this is what I am trying to do. I have a listview that is

  • 0

this is what I am trying to do.
I have a listview that is populated from a xml resource file saved in /values/menu.xml

it has this code in it:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string-array name="menuchoices">
     <item name="pv">Present Value</item>
     <item name="fv">Future Value</item>
     <item name="bond">Bond Pricing</item>
 </string-array>   
</resources>

So far so simple. Then my Main.java file looks like this: (adapted from other listview questions here)

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ListView lv = (ListView) findViewById(R.id.listView1);
    lv.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            getResources().getStringArray(R.array.menuchoices)
            ));


}

public void onListItemClick(ListView partent, View v, int position, long id) {
   if ("pv".equals(getResources().getStringArray(R.array.menuchoices)[position])){
       setContentView(R.layout.presentvalue);
   }
   }       
}

Basically I read that launching new activities all the time is not the best practice so i just told the if statement to change the contentview. The problem is — Nothing happens when i click on the first item in the list. i also tried substituting “pv” with “Present Value” but it did not help either.

I think this i beacuase i took the code from posts like this here List View selection to start a new Activity) but I don’t know how to change it so it works with the external xml resource file.

This should be a simple fix right?

THanks in advance

Max

P.s. all the other stuff works (the presentvalue.xml file is in the layout folder and the list is properly displayed when i run the app)

EDIT //

here is the problematic line

public void onListItemClick(ListView parent, View v, int position, long id) {
   if (view.getText().toString().equals("Present Value")){
       startActivity(new Intent(Main.this, PresentValue.class));
   }
   } 
  • 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-03T00:58:44+00:00Added an answer on June 3, 2026 at 12:58 am

    The function onListItemClick() is typically used with a ListActivity. There are a couple fixes to this:

      • Change the line extends Activity to extends ListActivity.
      • Remove your ListView definition.
      • Change your main.xml id from @+id/listView1 to @android:id/list
      • add implements OnItemClickListener in your class definition after extends Activity
      • Change the function onListItemClick to onItemClick

    Try moving your menuchoices block:

     <string-array name="menuchoices">
         <item name="pv">Present Value</item>
         <item name="fv">Future Value</item>
         <item name="bond">Bond Pricing</item>
     </string-array>   
    

    Into your string.xml file, then we can simplify your adapter (assuming you did changes #1 above):

    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            R.array.menuchoices));
    

    We can also condense how you test the menu choice:

    "pv".equals(getResources().getStringArray(R.array.menuchoices)[position])
    

    Becomes:

    view.getText().toString().equals("Present Value");
    

    (Minor point, you have a typo in the word “parent”)

    How’s that?

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

Sidebar

Related Questions

I have a ListView which is populated from a string-array resource. I'm trying to
I am trying to have a complex ListView that has a Title and Description
I am trying to have a tree display custom data that looks like this.
I have a listview which is populated by a SimpleCursorAdapter that is binding data
Doing some R&D for my company. We are trying to have a listView that
I have a ListView that I'm trying to add a footer to. For some
I have a listView, a main xml file and a customListview xml file. for
I have been trying desperately to fix this issue where my ListView items are
I have a ListView that uses different XML files to create Views and make
I have been trying this for hours without success. http://replicaisland.googlecode.com/svn/trunk/ I have added 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.