您在 1 中使用它的方式是将微调器的视图设置为唯一可见的视图。
您需要在 XML 文件中定义视图,然后将其设置为内容视图
例如 main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
然后在你的 .java 文件中
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//setting up the adapters
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
//adding things to the adapters
dataAdapter.add("English");
dataAdapter2.add("Spanish");
//setting the spinners up from their id in the XML file
Spinner spinner1 = (Spinner)findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner)findViewById(R.id.spinner2);
//setting the spinners adapters
spinner1.setAdapter(dataAdapter);
spinner2.setAdapter(dataAdapter2);
}
应该这样做,如果我对问题的解释有误,请更详细地回答。