私はN
の "本"をいくつかの章を持っています。そこで私はListView
を作成します。 ListView
の各項目には、名前の場合はTextView
、章の場合はSpinner
の2つの部分があります。Android:リストビューのスピナー、OnClick/OnItemClick/OnItemSelectedイベントはどこですか?
ListView
- BookAdapt
のカスタムアダプターとSpinner
- ChapAdapt
のカスタムアダプターを作成しました。私はそれを表示し、働いているが、私はクリック/選択されたイベントを追加する方法を見つけることができません。ここで
リストリソースここ
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load Chapter" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="Load"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="Cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<ListView
android:id="@+id/chapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
は、各書籍の表示ここで
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/viewbook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Spinner
android:id="@+id/chapspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/chapter_prompt"
android:layout_weight="1"/>
はBookAdapt
class BookAdapt extends ArrayAdapter {
BookAdapt(Context context, int txtres, BookHolder[] bks) {
super(context, txtres);
mContext = context;
books = bks;
mInflater = LayoutInflater.from(context);
}
public View getView(int pos, View convert, ViewGroup parent) {
BookHolder book = books[ pos];
String bkname = book.getName();
if (convert == null) {
convert = mInflater.inflate(R.layout.bookview, null);
book.text = (TextView) convert.findViewById(R.id.viewbook);
Spinner sp = (Spinner)convert.findViewById(R.id.chapspinner);
ChapAdapt ch = new ChapAdapt(book, mContext);
sp.setAdapter(ch);
//convert.setClickable(true);
convert.setTag(book);
} else {
book = (BookHolder)convert.getTag();
}
book.text.setText(bkname);
return convert;
}
ChapAdapt
にはTexTView
が割り当てられます。