HomeExpandableListView
is a custom extension of
* ExpandableListView, that packs a HomeContextMenuInfo
* when any of its rows is long pressed.
*
* This is the ExpandableListView
equivalent of
* HomeListView
.
*/
public class HomeExpandableListView extends ExpandableListView
implements OnItemLongClickListener {
// ContextMenuInfo associated with the currently long pressed list item.
private HomeContextMenuInfo mContextMenuInfo;
// ContextMenuInfo factory.
private HomeContextMenuInfo.ExpandableFactory mContextMenuInfoFactory;
public HomeExpandableListView(Context context) {
this(context, null);
}
public HomeExpandableListView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HomeExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setOnItemLongClickListener(this);
}
@Override
public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
if (mContextMenuInfoFactory == null) {
return false;
}
// HomeExpandableListView items can correspond to groups and children.
// The factory can determine whether to add context menu for either,
// both, or none by unpacking the given position.
mContextMenuInfo = mContextMenuInfoFactory.makeInfoForAdapter(view, position, id, getExpandableListAdapter());
return showContextMenuForChild(HomeExpandableListView.this);
}
@Override
public ContextMenuInfo getContextMenuInfo() {
return mContextMenuInfo;
}
public void setContextMenuInfoFactory(final HomeContextMenuInfo.ExpandableFactory factory) {
mContextMenuInfoFactory = factory;
}
}