2016-07-31 8 views
0

私は、という名前のクラスを持っています。これは、BaseExpandableListAdapterを拡張するExpandableListAdapterです。マイgetChildView方法は、次のようになります。をActTrainingAndroid - ExpandableListAdapterでリスナーを正しく配置する

@Override 
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, 
     ViewGroup parent) { 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) this.context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_item, null); 
    } 

    tv_questionAmountResult = (TextView) convertView.findViewById(R.id.tv_questionAmountResult); 
    tv_correctAmountResult = (TextView) convertView.findViewById(R.id.tv_correctAmountResult); 
    tv_wrongAmountResult = (TextView) convertView.findViewById(R.id.tv_wrongAmountResult); 

    bt_allQuestions = (Button) convertView.findViewById(R.id.bt_allQuestions); 
    bt_correctQuestions = (Button) convertView.findViewById(R.id.bt_correctQuestions); 
    bt_wrongQuestions = (Button) convertView.findViewById(R.id.bt_wrongQuestions); 

    return convertView; 
} 

私の他のクラスはのonCreateメソッド内ExpandableListAdapterを使用している:

ExpandableListAdapter listAdapter; 
ExpandableListView expListView; 

    // get the listview 
    expListView = (ExpandableListView) findViewById(R.id.topicExpandableListView); 

    // preparing list data 
    prepareListData(); 

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); 

    // setting list adapter 
    expListView.setAdapter(listAdapter); 

今、私は3つのボタンのためにOnClickListener追加したいが、私は」正しい配置ではわかりません。 getChildViewまたはActTrainingクラスにリスナーを追加する必要がありますか?

答えて

0

すべての3つのボタンについてはExpandableListAdapter.getChildViewOnClickListenerを入れなければなりません。すべての子アイテムにボタンがあるからです。ハンドルOnClickListenerため

いくつかの有用なリンク:

RecyclerView click listener

Set a click listener to a RecyclerView

+0

問題は、私のExpandableListAdapterアクティビティを延長しないことです。だから私はstartActivity()を使うことはできません。 –

+0

あなたは 'callback'メソッドを作成し、それをインタフェースに入れ、' onClickListener'で呼び出してから、あなたのアクティビティでコールバックを実装することができます。私は答えを編集し、いくつかの便利なリンクを追加します。 – SadeghAlavizadeh

関連する問題