1

塊擴展我開發一個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; 
    } 
}); 

任何一個能幫助我嗎?

回答

1

ExpandableListView.PACKED_POSITION_TYPE_GROUP是一個組的ID,將其更改爲 ExpandableListView.PACKED_POSITION_TYPE_CHILD並且您可以在組子節點上使用longclicks進行操作。

類似的東西:

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; 
} 
}); 
+0

你能給予好評我闕嗎? – shafeeq

0
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; 
     } 
    }); 

} 
+0

我認爲這樣可以適合你。 :) –