2011-01-29 9 views
0

私は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が割り当てられます。

答えて

0

スピナー自体がOnClicklistenerを実装しているため、ポップアップしてそれぞれの項目を選択することができます。選択後、Spinner.onClick()がシステムから呼び出されますので、これがあなたが探している場所だと思います。

あなたがしようとしていることは、私にとってExpandableListViewのユースケースのように聞こえるかもしれません。おそらく面白いかもしれません。

関連する問題