这是我想要得到的布局。只要我实际上不尝试填充我的微调器,一切都加载得很好。根据我在搜索中发现的内容和日志,我需要将 TextView 与 ArrayAdapter 一起使用。在保留当前布局的同时,我究竟是如何做到这一点的——微调器和顶部的提交按钮以及用于在微调器下方返回结果的 ListView 是我无法实现的。
这是我的 onCreate 方法。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.master);
DBHelper db = new DBHelper(this);
List<Stations> st = db.getAllStations();
List<CharSequence> stations = new ArrayList<CharSequence>();
setList(4, 9);
for (int i = 0; i < st.size(); i++)
{
stations.add(st.get(i).getStation());
}
ListView list = (ListView) findViewById(R.id.list);
Spinner s1 = (Spinner) findViewById(R.id.spinnerStart);
Spinner s2 = (Spinner) findViewById(R.id.spinnerEnd);
ArrayAdapter<CharSequence> SimpleSpinner1 = new ArrayAdapter<CharSequence>(this, R.layout.spinner, R.id.textView1);
ArrayAdapter<CharSequence> SimpleSpinner2 = new ArrayAdapter<CharSequence>(this, R.layout.spinner, R.id.textView1);
SimpleAdapter nSchedule = new SimpleAdapter(this, departures, R.layout.row,
new String[] {"train", "from", "to"}, new int[] {R.id.TRAIN_CELL, R.id.FROM_CELL, R.id.TO_CELL});
for (CharSequence c : stations)
{
SimpleSpinner1.add(c);
SimpleSpinner2.add(c);
}
list.setAdapter(nSchedule);
s2.setAdapter(SimpleSpinner2);
s1.setAdapter(SimpleSpinner1);
}
大师.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Spinner
android:id="@+id/spinnerStart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<Spinner
android:id="@+id/spinnerEnd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/spinnerStart" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/spinnerEnd"
android:text="Button" />
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button1"
layout="@layout/listview" />
</RelativeLayout>
微调器.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>