所以,我想知道是否有任何方法可以为可扩展列表视图设置onclickListner ..
我知道当你没有用“HashMap”实现Child数据时,它是可能的。
这是我的代码。我厌倦了所有可能的onclick侦听器的hashmap方法。但还没有成功。
在这里输入代码
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;
}
}
答案 0 :(得分: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;
}
});