0

こんにちは、展開可能なリストで子をクリックして、親の値を変更しようとしています。解決策を探しましたが、何も見つかりません。

public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int              childPosition, long id){
            ExpandableListAdapter itemAdapter = parent.getExpandableListAdapter();
            String selectedItem = (String)itemAdapter.getChild(groupPosition, childPosition);
            groupHeader(selectedItem);
            if(parent.isGroupExpanded(groupPosition)){
                parent.collapseGroup(groupPosition);
            }

            return true;
        }

    });
4

1 に答える 1

0

ExpandableListView は、アダプタに依存してその値を取得します。これらの値は、多くの場合 ArrayList や単純な配列など、ある種のデータ構造から取得されます。onChildClick() で、ExpandableListAdapter の作成に使用されるデータ構造への参照を渡し、データ構造を直接変更してから、notifyDataSetChanged() を呼び出します。

public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
{
        ExpandableListAdapter itemAdapter = parent.getExpandableListAdapter();
        String selectedItem = (String)itemAdapter.getChild(groupPosition, childPosition);
        groupHeader(selectedItem);
        if(parent.isGroupExpanded(groupPosition))
        {
            parent.collapseGroup(groupPosition);
        }
        // your logic here
        // expandableListArrayList.add() or expandableListArrayList.remove()
        // or whatever 
        itemAdapter.notifyDataSetChanged();

        return true;
    }
});

必要な機能を作成するには、おそらくアダプターを拡張する必要があります。あなたの質問は、あなたのコードの全体的な構造を見ることができないので、少し漠然としていますが、これはあなたにランニングスタートを与えるはずです.

于 2013-05-05T22:45:21.827 に答える