0

我想知道,我怎样才能得到被点击的对象ExpandableListView

我有一个BaseExpandableListAdapter,这是我的方法:

@Override
public View getChildView(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    final Foo children = (Foo) getChild(groupPosition, childPosition);
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.list_item, null);
    }

    // view stuff

    convertView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // how to get the clicked child object of type Foo?
        }
    });

    convertView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // also how to get it here?
            return true;
        }
    });

    return convertView;
}

如何获取Foo单击和长单击侦听器的子元素类型?

4

1 回答 1

0

在代码中使用onChildClick方法。单击子项时会自动调用此方法。使用 链接进行长按。

 public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {

            return true;
        }
于 2013-10-09T09:14:59.717 回答