我試圖解決我的微調教程,但它似乎沒有顯示標題。任何人都可以指導我關於哪一部分,我可能會忽略?android Spinner方法
public class HelloSpinnerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinnertest = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.Planets, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnertest.setAdapter(adapter);
spinnertest.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "The planet is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
}
main.xml中
<Spinner
android:id="@+id/Spinner01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:prompt = "@string/planet_prompt"
android:entries ="@array/Planets">
</Spinner>
的strings.xml
<string name="app_name">Spinner</string>
<string name="planet_prompt"> Select a planet </string>
<string-array name="Planets">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
<item>Pluto</item>
</string-array>
請發佈一個問題的快照。 – 2011-12-19 09:24:03
添加您的異常frm您的LogCat的堆棧 – Houcine 2011-12-19 10:16:00
可能的重複[如何使用初始文本「選擇一個」的Android微調器](http://stackoverflow.com/questions/867518/how-to-make-an- Android的微調與 - 初始文本選擇一) – blahdiblah 2013-03-09 11:28:02