0

3 つのレベルを持つ ExpandableListView があります。最初のレベルのアダプターには、TextView をレンダリングする getGroupView があり、正常に動作します。

@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だけでなく、ボタンも持っています。それにもかかわらず、行をクリックしても展開されないため、機能しません。これは適応されたメソッドであり、もちろん、コンストラクターでインフレータを初期化します。

@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 を変更しているだけなので、本当に奇妙です..

よろしくお願いします!

4

1 に答える 1

0

私はこのようにそれを行います:

アクティビティクラス:

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

クラスでは、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;
}

このようにして、グループアイテムに何か他のことをするためのボタンがありながら、グループアイテムを展開できます。これを行うためのより良い方法があるはずです。しかし、私はそれについて勉強する時間がありません。

于 2012-09-04T10:32:00.007 に答える