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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:43:48+00:00 2026-05-23T03:43:48+00:00

My app has a main menu, and I am using a ListView to represent

  • 0

My app has a main menu, and I am using a ListView to represent it. Since it’s a menu, I will be implementing actions based on which item a user clicks on.

My current implementation looks like this:

  • In strings.xml, I have a string array of the names of the menu items.
  • In the main menu’s activity, I inflate the string array: itemList = getResources().getStringArray(R.array.main_menu_array); (itemList is a static String[])
  • Then I set an adapter for the ListView: listView.setAdapter(new ArrayAdapter<String>(this, R.layout.main_menu_item, itemList)); (R.layout.main_menu_item specifies the layout for each individual menu item. It basically is just a TextView with a couple of attributes.)
  • I set up an OnItemClickListener for the ListView.

The anonymous OnItemClickListener class implements onItemClick() like this

public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    switch (position) {
    case POS_ITEM_A:
        ... break;
    case POS_ITEM_B:
        ... break;
    }
}

POS_ITEM_A and POS_ITEM_B are final static variables set to 0 and 1 respectively.

I don’t think this is good code. How can I fix it?

  • 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-23T03:43:49+00:00Added an answer on May 23, 2026 at 3:43 am

    You could do that with a spinner but the code will be almost the same.

    Another alternative, simpler but that is less extensible is to work with AlertDialog.Buidler and use the setMultipleChoices method. Or this general documentation page.

    But a listview is not that bad. For a small feature, I suggest the dialog builder, for manipulating the main objects of your app, use a list view or spinner.

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

Sidebar

Related Questions

I'm working on an app which has a main menu which then switches views
I have a document-based Core Data app. My main Core Data entity has several
My app has several buttons which trigger different events. The user should NOT be
I'm making an app which has a flow roughly as below: User starts on
My app has a main screen that the user always starts at, and from
My main view controller (representing the Main Menu in my app) has a simple
if you make an app that has a main menu does every one of
My app's main view has a uiwebview. It is white for a split second
I am working on an app whose main window has an NSDrawer. It is
When my iPhone app starts up, the main screen has a keyboard. Currently 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.