Reputation: 44385
In android I define a layout as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:columnCount="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar_setting"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
<Spinner
android:id="@+id/settings_interval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title"/>
...
But some some reason the android:promp
text for the spinner is not shown when I start the corresponding activity. For completeness here is that activity:
public class SettingsActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
// Set toolbar, allow going back.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_setting);
//toolbar.setDisplayHomeAsUpEnabled(true);
//toolbar.setTitle("Settings");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Settings");
Spinner spinner = (Spinner) findViewById(R.id.settings_interval);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.listValues, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
}
Upvotes: 1
Views: 2371
Reputation: 1875
This is a code from Spinner
class:
public void setPromptText(CharSequence hintText) {
// Hint text is ignored for dropdowns, but maintain it here.
mHintText = hintText;
}
It looks like spinner ignore prompt in dropDown mode. Try to set android:spinnerMode="dialog"
to check.
Also you can look here to solve this.
Upvotes: 1