0

次のコードは現在アクティビティで動作しています。しかし、フラグメントに使用したいのですが、試してみると、展開可能なリストが認識されません。誰かがこれで私を助けることができれば、大きな助けになるでしょう.

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_expandable_list);
    createGroupList();
    createCollection();
    expListView = (ExpandableListView) findViewById(R.id.my_exp_list);
    final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(
            this, groupList, laptopCollection);
    expListView.setAdapter(expListAdapter);

    setGroupIndicatorToRight();

    expListView.setOnChildClickListener(new OnChildClickListener() {

        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            final String selected = (String) expListAdapter.getChild(
                    groupPosition, childPosition);
            Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG)
                    .show();

            return true;
        }
    });
}

私のフラグメントoncreateViewで、

View v = inflater.inflate(R.layout.activity_expandable_list, container, false);  createGroupList();
    createCollection();
    expListView = (ExpandableListView) inflater.inflate(R.id.my_exp_list, container, false);
4

1 に答える 1

1

あなたは2つの異なるビューを膨らませているか、少なくともしようとしています。次のように、ビューを膨らませてから、ExpandableListView で参照を取得する必要があります。

View v = inflater.inflate(R.layout.activity_expandable_list, container, false);
createGroupList();
createCollection();
expListView = (ExpandableListView) v.findViewById(R.id.my_exp_list);

上で膨らませたレイアウトで Expandable ListView が参照されていると思うので、これはうまくいくはずです。

于 2013-09-16T08:20:04.883 に答える