我正在尝试禁用ExpandableListView
当前选择的列表项的可点击性(以避免重新加载同一项的记录),但是尝试在其中设置view.Clickable = false;
或view.Enabled = false;
Adapter
的{{1}}替代似乎无效。
当前选定/突出显示的列表项(GetChildView
)设置为:
LinearLayout
ExpandListAdapter
SetItemChecked(_selectedViewFlatPosition, true);
SetSelection(_selectedViewFlatPosition);
答案 0 :(得分:0)
我改为在OnChildClick
内的ExpandableListView
侦听器中处理了它
public ExpandableListView(Context context, IAttributeSet attributes)
: base(context, attributes)
{
ChildClick += OnChildClick;
}
public void OnChildClick(object o, ChildClickEventArgs a)
{
//ExpandableListView parent = a.Parent;
//View view = a.ClickedView;
int groupPosition = a.GroupPosition;
int childPosition = a.ChildPosition;
//long id = a.Id;
// ignore re-selection (which will reload current record)
if (groupPosition == _selectedItemGroupPosition
&& childPosition == _selectedItemChildPosition)
{
return;
}
// or, alternatively
if (_selectedItemFlatPosition == GetFlatListPosition(GetPackedPositionForChild(groupPosition, childPosition)))
{
return;
}
var adapter = (ExpandListAdapterX)ExpandableListAdapter;
int childType = adapter.GetChildType(groupPosition, childPosition);
switch ((ChildTypes)childType)
{
case ChildTypes.GroupButtonBar:
break;
case ChildTypes.ListItem:
_selectedViewFlatPosition = GetFlatListPosition(GetPackedPositionForChild(groupPosition, childPosition));
SetItemChecked(_selectedViewFlatPosition, true);
ClearSelectedListItem();
// needs mvvm observation
List[groupPosition].SelectedItem = List[groupPosition][childPosition - 1];
_selectedItemGroupPosition = groupPosition;
_selectedItemChildPosition = childPosition;
ListItemClicked?.Invoke(this, new ListItemClickEventArgs(groupPosition));
break;
}
}