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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:52:57+00:00 2026-06-12T04:52:57+00:00

I am trying to add the ability for a user to add an item

  • 0

I am trying to add the ability for a user to add an item to a context menu.

The XML array for the menu is currently:

<array name="serverchoice">
    <item>@string/chicago_server</item>
    <item>@string/london_server</item>
    <item>@string/sanjose_server</item>
    <item>@string/washington_server</item>
    <item>@string/chicagoq_server</item>
    <item>@string/londonq_server</item>
    <item>@string/sanjoseq_server</item>
    <item>@string/washingtonq_server</item>
</array>

As you can see it’s a list of servers, I’d like a user to be able to add their own server rather than having to use the preset servers.

I have created a page with a text box and a button so a user can enter a server. When the user clicked the Add Server button I’d like the entry to be added to the list.

The way I’m currently processing the menu items when clicked is below:

    // Choose Server method

    private void openServerDialog() {
        new AlertDialog.Builder(this)     
        .setTitle(R.string.server_title)  
        .setItems(R.array.serverchoice,   
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface,
                    int i) {
                setServer(i);   
            }
        })
        .show();
    }

private void setServer(int i) {   


        if (String.valueOf(i).equals("0")){
            CustomServer.setText("mcsord.visualware.com");
        }
        else if (String.valueOf(i).equals("1")){
            CustomServer.setText("mcslhr.visualware.com");
            }
        else if (String.valueOf(i).equals("2")){
            CustomServer.setText("mcssjc.visualware.com");
            }
        else if (String.valueOf(i).equals("3")){
            CustomServer.setText("mcsiad.visualware.com");
            }
        else if (String.valueOf(i).equals("4")){
            CustomServer.setText("qualitytestord.visualware.com");
            }
        else if (String.valueOf(i).equals("5")){
            CustomServer.setText("qualitytestlhr.visualware.com");
            }
        else if (String.valueOf(i).equals("6")){
            CustomServer.setText("qualitytestsjc.visualware.com");
            }
        else if (String.valueOf(i).equals("7")){
            CustomServer.setText("qualitytestiad.visualware.com");
            }

}

So my next question is how would I then process the new entry.

Either way the first step is getting the new entry added to the list.

Any help would be great.

Thanks

  • 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-12T04:52:58+00:00Added an answer on June 12, 2026 at 4:52 am

    You wouldn’t be able to store the user’s input into the array resource that holds the servers you statically created. You would have to store the server the user entered into a file that you save into the phone’s memory, a SQLite database or using the Share Preferences (recommended). [http://developer.android.com/guide/topics/data/data-storage.html].

    In answer to your second question, I may have gone with a different overall approach.

    In your entry point for you application set up your system using the shared preferences

    // Shared Preference string
    public static final String PREFS = "SomeName";
    // Editor to customize preferences
    private Editor settingsEditor;
    // Shared preference
    private SharedPreferences prefs;
    //list that will hold all the servers for the menu
    private ArrayList<String> menuList = new ArrayList<String>();
    

    in your onCreate method (the very first time the user opens the application) you’re going to put your defined server names into the system

    prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
    
    // Get shared preferences and set up the preference editor
    settingsEditor = prefs.edit();
    
    // See if the app has been initialized
    if (!prefs.getString("initialized", "").equals("yes")) {
    
    settingsEditor.putString("server0","mcsord.visualware.com");
    settingsEditor.putString("server1","mcslhr.visualware.com");   
    
    //...do the above step to put the rest of them in
    settingsEditor.putInt("menuItemsCount",8);
    settingsEditor.putBoolean("initialized", true);
    settingsEditor.commit();
    }
    

    Afterward, you’re going to want to populate your menu list

    int i = prefs.getInt("menuItemCount", 0);
    for(j = 0; j < i; j++)
         menuList.add(prefs.getString("sever" + j,"");
    

    And now what you do is after the user opens the page, types in their server name and clicks the button:
    If it’s a dialog box that’s in the same activity you can add it to the list and the the shared preferences
    If it’s in another activity, send it through and intent, override the onActivityResult method and then add the string to the list and the shared preferences.

    In your onCreateContextMenu method, loop through the list that contains all the servers and add them to your menu. Lastly you could do this in your code

    private void openServerDialog() {
             new AlertDialog.Buildr(this)
                  .setTitle(R.string.server_title)
                  .setItems(R.array.serverchoice,
                  new DialogInterface.OnClickListener(){
                      public void onClick(DialogInterface dialoginterface,
                      int i) {
                         CustomServer.setText(menuList.get(i));
                  }
              }).show();
    }
    

    Hope this helps.

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

Sidebar

Related Questions

So I'm trying to add some ability to my project to allow user-defined properties
I'm trying add data triggers to the default combobox style so each text item
Using MS Visual C++ and Boost asio, I'm trying to add the ability to
I would like to add the ability for a user to launch the Add
My problem is I'm trying to add user controls to a page dynamically after
I have a WinForms app and am trying to add the ability to start
I am trying to add an ability to allow users of a wvb app
I am trying to implement the ability for a user to draw and refine
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got

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.