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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:52+00:00 2026-05-27T03:30:52+00:00

In an android website, I found an article about a widget similar to a

  • 0

In an android website, I found an article about a widget similar to a drop-down list for selecting items. (Following is the link to the site; and it shows all the codes).

http://developer.android.com/resources/tutorials/views/hello-spinner.html

It uses the following code to display a message once you have selected a planet.

Toast.makeText(parent.getContext(), "Mars Selected", Toast.LENGTH_LONG).show();

But this message “Planet is Selected” is only going to display for about 3 seconds and then it disappears. how can I output the “Mars Selected” message as a text layout in to the screen(So that it will stay on the screen permanently till I select another item from the list)? How can I use addView(tv) instead of setContentView(tv) Any help would be greatly appreciated.

public class MyOnItemSelectedListener implements OnItemSelectedListener {

   public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) 
   {                   
       if (parent.getItemAtPosition(pos).toString().equals("Mars"))
       {      TextView tv = new TextView(HelloSpinner.this); 
              tv.setText(parent.getItemAtPosition(pos).toString() + "Mars Selected");
              setContentView(tv); //How can I use addView(tv); here?
              //Toast.makeText(parent.getContext(), "Mars Selected", Toast.LENGTH_LONG).show();

       }if (parent.getItemAtPosition(pos).toString().equals("Earth"))
       {      TextView tv = new TextView(HelloSpinner.this); 
              tv.setText(parent.getItemAtPosition(pos).toString() + "Earth Selected");
              setContentView(tv); //How can I use addView(tv); here?
              //Toast.makeText(parent.getContext(), "Earth Selected", Toast.LENGTH_LONG).show();
       }
   }

   public void onNothingSelected(AdapterView parent) 
   {
         // Do nothing.
   } }

enter image description here

  • 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-27T03:30:53+00:00Added an answer on May 27, 2026 at 3:30 am

    Just add another textview below the spinner like

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:padding="10dip"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <TextView android:layout_width="fill_parent" 
            android:layout_height="wrap_content" android:layout_marginTop="10dip" 
            android:text="@string/planet_prompt"/>
        <Spinner android:id="@+id/spinner" android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:prompt="@string/planet_prompt"/>
        <TextView android:layout_width="fill_parent" 
            android:layout_height="wrap_content" android:layout_marginTop="10dip" 
            android:id="@+id/label"/>
    </LinearLayout>
    

    Then in your code do some thing like

    TextView label = (TextView)findViewById(R.id.label);
    label.setText(THE STRING FROM THE SPINNER);
    

    Ideally you should only call setContentView one time during onCreate. To updated the screen you should add and remove view and not call setContentView multiple times.

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

Sidebar

Related Questions

in an android website, I found an article about how to create a text
I've been keen to learn about triggers in Android and SQLite. I found a
On the Android developers website, there is a Notepad tutorial and I found a
On the android website, there is a section about color drawables . Defining these
I'm following the MapView tutorial on the Android website [2010-08-22 11:12:24 - com.android.ide.eclipse.adt.internal.project.AndroidManifestParser] Parser
I'm planning to use my website to provide updates for my android application whenever
I am making an HTTP get request to a website for an android application
When android unbind a service I created (service.MyService), I see the following DeadObjectException. Can
I have a website designed for the android browser using jquery/jqtouch. As a part
today i came across a new app-store for Android called soc.io. The website looks

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.