これが私が取得しようとしているレイアウトです。スピナーに実際にデータを入力しようとしない限り、すべてが正常に読み込まれます。検索とログで見つけたものに基づくと、ArrayAdapterでTextViewを使用する必要があるということです。現在のレイアウトを維持しながら、正確にそれを行う方法-スピナーと、スピナーの下に返される結果の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);
}
master.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>
spinner.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>