长按阻止扩展可扩展列表视图
Block expanding of Expandable List View on long click
我正在开发一个 android 应用程序,我在其中使用 Expandablelistview
来显示一些数据。目前,列表视图将在点击组和长按后释放时展开。但是,我需要防止在长按时展开 Expandablelistview
。
我的代码段如下所示:
elvItemList = (ExpandableListView) root.findViewById(R.id.elv_item_list);
elvItemList.setOnGroupClickListener(this);
elvItemList.setAdapter(smListAdapter);
elvItemList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
Utils.logit("SMLOG", "Long button pressed");
//
}
return false;
}
});
谁能帮帮我?
ExpandableListView.PACKED_POSITION_TYPE_GROUP
是群的id,改成
ExpandableListView.PACKED_POSITION_TYPE_CHILD
您可以通过长按子组进行操作。
类似的东西:
elvItemList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
// Your code with group long click
return true;
}
return false;
}
});
public void stopExpandOnLongClick()
{
expListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
boolean checkClick=false;
long packedPosition = expListView.getExpandableListPosition(position);
int itemType = ExpandableListView.getPackedPositionType(packedPosition);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
/* if group item clicked */
if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
// ...
if(expListView.isGroupExpanded(groupPosition))
{
Toast.makeText(MainActivity.this, "It's normal group collaspe", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.this, "This Grouo is not going to expand on long click", Toast.LENGTH_LONG).show();
//you can put your logic when you long press on Group header
checkClick=true;
}
}
return checkClick;
}
});
}
这对我有用。
expandableListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return true; // Change return false; to return true;
}
});
我正在开发一个 android 应用程序,我在其中使用 Expandablelistview
来显示一些数据。目前,列表视图将在点击组和长按后释放时展开。但是,我需要防止在长按时展开 Expandablelistview
。
我的代码段如下所示:
elvItemList = (ExpandableListView) root.findViewById(R.id.elv_item_list);
elvItemList.setOnGroupClickListener(this);
elvItemList.setAdapter(smListAdapter);
elvItemList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
Utils.logit("SMLOG", "Long button pressed");
//
}
return false;
}
});
谁能帮帮我?
ExpandableListView.PACKED_POSITION_TYPE_GROUP
是群的id,改成
ExpandableListView.PACKED_POSITION_TYPE_CHILD
您可以通过长按子组进行操作。
类似的东西:
elvItemList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
// Your code with group long click
return true;
}
return false;
}
});
public void stopExpandOnLongClick()
{
expListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
boolean checkClick=false;
long packedPosition = expListView.getExpandableListPosition(position);
int itemType = ExpandableListView.getPackedPositionType(packedPosition);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
/* if group item clicked */
if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
// ...
if(expListView.isGroupExpanded(groupPosition))
{
Toast.makeText(MainActivity.this, "It's normal group collaspe", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.this, "This Grouo is not going to expand on long click", Toast.LENGTH_LONG).show();
//you can put your logic when you long press on Group header
checkClick=true;
}
}
return checkClick;
}
});
}
这对我有用。
expandableListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return true; // Change return false; to return true;
}
});