0

所以,我想知道是否有任何方法可以为可扩展列表视图设置 onclickListner。
我知道当您没有使用“HashMap”实现子数据时,这是可能的。这是我的代码。我厌倦了 hashmap 方法的所有可能的 onclick 侦听器。但还没有成功。

在这里输入代码

package com.prashant.dfs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ExpandableListView;

public class Chapter_1_full extends Activity {


ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> ListDataHeader;
HashMap<String,List<String>> listDataChild;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chapter_1_full);

    //get the listView(expand)
    expListView = (ExpandableListView) findViewById(R.id.ch1_expand);
    //prepareDataList
    prepareListData();

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

    expListView.setAdapter(listAdapter);
}

private void prepareListData() {
    ListDataHeader = new ArrayList<String>();
    listDataChild=new HashMap<String, List<String>>();
    //Adding child Data

    ListDataHeader.add("1.1 Introductin");
    ListDataHeader.add("1.2 DataType");
    ListDataHeader.add("1.3 ADT");


    List<String> Intro = new ArrayList<String>();
    Intro.add("WHAT is DFS");
    Intro.add("Algorithem");
    Intro.add("Flowchart");


    List<String> datatype = new ArrayList<String>();
    datatype.add("WHAT is DFS");
    datatype.add("Algorithem");
    datatype.add("Flowchart");


    List<String> ADT = new ArrayList<String>();
    ADT.add("WHAT is DFS");
    ADT.add("Algorithem");
    ADT.add("Flowchart");


    listDataChild.put(ListDataHeader.get(0),Intro);
    listDataChild.put(ListDataHeader.get(1),datatype);
    listDataChild.put(ListDataHeader.get(2),ADT);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.chapter_1_full, menu);
    return true;
}

}

4

1 回答 1

0

好吧,假设您的适配器正确地实现了它的方法......

    expandableListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(final ExpandableListView parent, final View view, final int groupPosition, final int childPosition,
                final long identifier) {

            final Object childObj = parent.getExpandableListAdapter().getChild(groupPosition, childPosition);

            if (childObj != null) {

                // Do your magic
            }

            return true;
        }
    });
于 2013-10-11T15:42:04.607 回答