巴顿在ExpandableListView一行 [英] Button in a row in ExpandableListView

查看:118
本文介绍了巴顿在ExpandableListView一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个层次的ExpandableListView。
在适配器的第一级,我有这使得一个TextView的getGroupView,并能正常工作。

I have an ExpandableListView with three levels. In the adapter for the first level, I have the getGroupView which renders a TextView, and it works fine.

@Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
             TextView tv = new TextView(context);
             tv.setText(mCountries.get(groupPosition).getName());
             tv.setBackgroundColor(Color.BLUE);
             tv.setPadding(10, 7, 7, 7);
             return tv;
        }

但现在我想把它带到一个新的水平..只是一个充气XML和有,而不只是一个TextView,一个按钮太多;然而,它不工作,那么,因为当我点击一排它不会扩大。
这是适于方法,当然,在构造,我初始化充气

But now I wanted to take it to the next level.. just inflating an XML and have instead of just a TextView, a Button too; nevertheless, it doesn't work then, since it doesn't expand when I click on a row. This is the adapted method, and of course, in the constructor, I initialize the inflater:

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View v = mInflater.inflate(R.layout.countries_row, null, false);
        mCountryName = (TextView) v.findViewById(R.id.CountryTextView);
        mCountryName.setText(mCountries.get(groupPosition).getName());
        mCountryName.setBackgroundColor(Color.BLUE);
        mCountryName.setPadding(10, 7, 7, 7);
        mCountryExpandButton = (Button) v.findViewById(R.id.CountryExpandButton);
        return v;
    }

mInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

任何人能请扔在它为什么不工作的一些光,以及如何解决它?
这真是奇怪,因为它只是改变一个TextView的视图。

Can anybody please throw some light on why it doesn't work, and how to fix it? It's really strange because it's just changing a TextView for a View..

非常感谢事先!

推荐答案

我这样做是这样的:

在活动类:

public void expandGroup(int groupPosition)
{
    if(expandableListView.isGroupExpanded(groupPosition))
        expandableListView.collapseGroup(groupPosition);
    else
        expandableListView.expandGroup(groupPosition);
}

在类扩展BaseExpandableListAdapter:

In the class extends BaseExpandableListAdapter:

public View getGroupView(final int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    LayoutInflater inflater=LayoutInflater.from(acti);
    View rtnview=inflater.inflate(R.layout.XXX, null);
    TextView text=(TextView)rtnview.findViewById(R.id.tvinfo1);
    text.setText(groupArray.get(groupPosition));
    text.setTextColor(acti.getResources().getColor(R.color.blackcolor));
text.setTextSize(EDEnv.EEfontSize+3);
text.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            acti.expandGroup(groupPosition);
        }
});
    Button btn1=(Button)rtnview.findViewById(R.id.button1);
    btn1.setId(groupPosition);
    btn1.setOnClickListener(new Button.OnClickListener(){
    public void onClick(View v)
    {
        acti.showDialog(1);
    }
});
    if (convertView == null) {
        convertView = rtnview;
    }
    return convertView;
}

通过这种方式可以展开该组项目而对项目组的一个按钮做别的事情。必须有一个更好的方式来做到这一点。但我没有时间来研究它。

By this way you can expand the group item while has a button on the group item to do something else. There must be a better way to do this. But I don't have time to study on it.

这篇关于巴顿在ExpandableListView一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆