package com.zeus.eca;import androID.app.ExpandableListActivity;import androID.content.res.Resources;import androID.graphics.Typeface;import androID.os.Bundle;import androID.vIEw.Gravity;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.AbsListVIEw;import androID.Widget.Baseexpandablelistadapter;import androID.Widget.expandablelistadapter;import androID.Widget.ExpandableListVIEw;import androID.Widget.TextVIEw;public class ListCountrIEs extends ExpandableListActivity implements ExpandableListVIEw.OnChildClickListener{expandablelistadapter mAdapter;@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAdapter=new Myexpandablelistadapter();; setlistadapter(mAdapter); getExpandableListVIEw().setonChildClickListener(this); };@OverrIDepublic boolean onChildClick(ExpandableListVIEw parent,VIEw v,int groupposition,int childposition,long ID) { // Todo auto-generated method stub return false; //return true;} public class Myexpandablelistadapter extends Baseexpandablelistadapter { // Sample data set. children[i] contains the children (String[]) for groups[i]. private String[] groups ={"Africa","Asia","Europe","north America","South America","Oceania","Antartica"}; Resources res = getResources(); private String[] strAfrica=res.getStringArray(R.array.arrayAfrica); private String[] strAsia=res.getStringArray(R.array.arrayAsia); private String[] strEurope=res.getStringArray(R.array.arrayEurope); private String[] strnamerica=res.getStringArray(R.array.arraynamerica); private String[] strSAmerica=res.getStringArray(R.array.arraySAmerica); private String[] strOceania=res.getStringArray(R.array.arrayOceania); private String[] strAntartica=res.getStringArray(R.array.arrayAntartica); private String[][] children = { strAfrica,strAsia,strEurope,strnamerica,strSAmerica,strOceania,strAntartica }; public Object getChild(int groupposition,int childposition) { return children[groupposition][childposition]; } public long getChildID(int groupposition,int childposition) { return childposition; } public int getChildrenCount(int groupposition) { return children[groupposition].length; } public TextVIEw getGenericVIEw() { // Layout parameters for the ExpandableListVIEw AbsListVIEw.LayoutParams lp = new AbsListVIEw.LayoutParams( VIEwGroup.LayoutParams.FILL_PARENT,55); TextVIEw textVIEw = new TextVIEw(ListCountrIEs.this); textVIEw.setLayoutParams(lp); // Center the text vertically textVIEw.setGravity(Gravity.CENTER_VERTICAL | Gravity.left); textVIEw.setTypeface(Typeface.DEFAulT_BolD); // Set the text starting position textVIEw.setpadding(36,0); // textVIEw.setBackgroundResource(R.drawable.colorWhite); // textVIEw.setTextcolor(getResources().getcolor(R.color.colorBackground)); return textVIEw; } public VIEw getChildVIEw(int groupposition,boolean isLastChild,VIEw convertVIEw,VIEwGroup parent) { TextVIEw textVIEw = getGenericVIEw(); textVIEw.setText(getChild(groupposition,childposition).toString()); return textVIEw; } public Object getGroup(int groupposition) { return groups[groupposition]; } public int getGroupCount() { return groups.length; } public long getGroupID(int groupposition) { return groupposition; } @OverrIDe public VIEw getGroupVIEw(int groupposition,boolean isExpanded,VIEwGroup parent) { TextVIEw textVIEw = getGenericVIEw(); textVIEw.setText(getGroup(groupposition).toString()); return textVIEw; } public boolean isChildSelectable(int groupposition,int childposition) { return true; } public boolean hasStableIDs() { return true; }}
}
解决方法 这应该工作@OverrIDepublic boolean onChildClick(ExpandableListVIEw parent,long ID) { String country = (String)mAdapter.getChild(groupposition,childposition); // update the text vIEw with the country return true;}总结
以上是内存溢出为你收集整理的想知道如何在可扩展列表ANDROID中获取所选项目全部内容,希望文章能够帮你解决想知道如何在可扩展列表ANDROID中获取所选项目所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)