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.
} }

Just add another textview below the spinner like
Then in your code do some thing like
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.