android – 从ExpandableListView中检索ChildItem?

android – 从ExpandableListView中检索ChildItem?,第1张

概述当用户点击ExpandableListView的子项时,我正在尝试检索childitem.因为我的Activity和ListAdapter类如下所示. 主要活动:- public class MainActivity extends Activity { NewAdapter mNewAdapter; @Override public void onCreate(Bun 当用户点击ExpandableListVIEw的子项时,我正在尝试检索childitem.因为我的Activity和listadapter类如下所示.

主要活动:-

public class MainActivity extends Activity {    NewAdapter mNewAdapter;    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        ExpandableListVIEw expandblelis = (ExpandableListVIEw) findVIEwByID(R.ID.expandableListVIEw);        expandblelis.setdivIDerHeight(2);        expandblelis.setGroupIndicator(null);        expandblelis.setClickable(true);        setGroupData();        setChildGroupData();        mNewAdapter = new NewAdapter(groupItem,childItem);        mNewAdapter                .setInflater(                        (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),this);        expandblelis.setAdapter(mNewAdapter);        expandblelis.setonGroupClickListener(new OnGroupClickListener() {            @OverrIDe            public boolean onGroupClick(ExpandableListVIEw parent,VIEw v,int groupposition,long ID) {                Toast.makeText(MainActivity.this,"GroupItem Clicked" + groupItem.get(groupposition),Toast.LENGTH_LONG).show();                return false;            }        });        expandblelis.setonChildClickListener(new OnChildClickListener() {            @OverrIDe            public boolean onChildClick(ExpandableListVIEw parent,int childposition,"ChildItem Clicked",Toast.LENGTH_LONG).show();                return false;            }        });    }    public voID setGroupData() {        groupItem.add("TechNology");        groupItem.add("Mobile");        groupItem.add("Manufacturer");        groupItem.add("Extras");    }    ArrayList<String> groupItem = new ArrayList<String>();    ArrayList<Object> childItem = new ArrayList<Object>();    public voID setChildGroupData() {        /**         * Add Data For TecthNology         */        ArrayList<String> child = new ArrayList<String>();        child.add("Java");        child.add("Drupal");        child.add(".Net Framework");        child.add("PHP");        childItem.add(child);        /**         * Add Data For Mobile         */        child = new ArrayList<String>();        child.add("AndroID");        child.add("Window Mobile");        child.add("iPHone");        child.add("BlackBerry");        childItem.add(child);        /**         * Add Data For Manufacture         */        child = new ArrayList<String>();        child.add("HTC");        child.add("Apple");        child.add("Samsung");        child.add("Nokia");        childItem.add(child);        /**         * Add Data For Extras         */        child = new ArrayList<String>();        child.add("Contact Us");        child.add("About Us");        child.add("Location");        child.add("Root Cause");        childItem.add(child);    }}

listadapter: –

public class NewAdapter extends Baseexpandablelistadapter {    public ArrayList<String> groupItem,tempChild;    public ArrayList<Object> Childtem = new ArrayList<Object>();    public LayoutInflater minflater;    public Activity activity;    public NewAdapter(ArrayList<String> grList,ArrayList<Object> childItem) {        groupItem = grList;        this.Childtem = childItem;    }    public voID setInflater(LayoutInflater mInflater,Activity act) {        this.minflater = mInflater;        activity = act;    }    @OverrIDe    public Object getChild(int groupposition,int childposition) {        return null;    }    @OverrIDe    public long getChildID(int groupposition,int childposition) {        return 0;    }    @OverrIDe    public VIEw getChildVIEw(int groupposition,final int childposition,boolean isLastChild,VIEw convertVIEw,VIEwGroup parent) {        tempChild = (ArrayList<String>) Childtem.get(groupposition);        TextVIEw text = null;        if (convertVIEw == null) {            convertVIEw = minflater.inflate(R.layout.childrow,null);        }        text = (TextVIEw) convertVIEw.findVIEwByID(R.ID.textVIEw1);        text.setText(tempChild.get(childposition));        return convertVIEw;    }    @OverrIDe    public int getChildrenCount(int groupposition) {        return ((ArrayList<String>) Childtem.get(groupposition)).size();    }    @OverrIDe    public Object getGroup(int groupposition) {        return null;    }    @OverrIDe    public int getGroupCount() {        return groupItem.size();    }    @OverrIDe    public voID onGroupCollapsed(int groupposition) {        super.onGroupCollapsed(groupposition);    }    @OverrIDe    public voID onGroupExpanded(int groupposition) {        super.onGroupExpanded(groupposition);    }    @OverrIDe    public long getGroupID(int groupposition) {        return 0;    }    @OverrIDe    public VIEw getGroupVIEw(final int groupposition,boolean isExpanded,VIEwGroup parent) {        // isExpanded = false;        if (convertVIEw == null) {            convertVIEw = minflater.inflate(R.layout.grouprow,null);        }        ((CheckedTextVIEw) convertVIEw).setText(groupItem.get(groupposition));        ((CheckedTextVIEw) convertVIEw).setChecked(isExpanded);        return convertVIEw;    }    @OverrIDe    public boolean hasStableIDs() {        return false;    }    @OverrIDe    public boolean isChildSelectable(int groupposition,int childposition) {        return true;    }}

我用Googled尝试了this,但没有用,我没有得到它的子项目.请帮忙这样做.

在尝试了许多可能的解决方案后,我发布这个请尝试帮助我不要投票,如果你投票下来说可能的解决方案然后我会同意..

解决方法 多个问题:

>需要选择子项才能使单击工作.更改适配器的isChildSelectable()以返回true.>从childrow.xml根linearLayout中删除androID:clickable =“true”. (或者,将一个点击处理程序添加到linearLayout本身.)>实现getGroup()和getChild()以返回实际对象而不是null,并使用getGroupID()和getChildID()返回本地唯一标识符.也就是说,组内的子ID必须是唯一的,但它们不需要在组之间是唯一的.在您的情况下,将子/组位置作为ID返回.

总结

以上是内存溢出为你收集整理的android – 从ExpandableListView中检索ChildItem?全部内容,希望文章能够帮你解决android – 从ExpandableListView中检索ChildItem?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127438.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存