2015-04-05 64 views
0

提及的波紋管是我正在爲long click listener事件註冊framelayout的代碼。framelayout上的setOnLongClickListener無法按預期方式工作

private void createActivityLayout(Fragment fragment) 
{ 
    FrameLayout frameLayout =  (FrameLayout)getLayoutInflater().inflate(R.layout.professional_pa_frame_layout, null, false); 

    frameLayout.setClickable(true); 

    frameLayout.setOnLongClickListener(new View.OnLongClickListener() 
    { 
     public boolean onLongClick(View view) 
     { 
      if (actionMode == null) 
      { 
       return false; 
      } 

      actionMode = view.startActionMode(actionModelCallback); 
      view.setSelected(true); 
      return false; 
     } 
    }); 

    getFragmentManager().beginTransaction().add(id, fragment, tag).commit(); 
} 

該片段內部包含一系列edittext實例或單個imageview實例。

無論何時在framelayout上執行長按操作,我都會顯示edittext的上下文操作欄。我認爲事件被editext捕獲,並顯示不同的上下文操作欄。每當我在framelayout中獲得長按事件時,都會顯示上下文操作欄的PFA圖像。

enter image description here

我如何能捕捉長按事件對我的FrameLayout作爲一個整體而不考慮其內部的意見顯示上下文操作欄。下面寫的xml代碼是我想爲我的framelayout顯示的上下文操作欄。

<item android:id="@+id/action_discard_notes" 
    android:icon="@drawable/discard_note" 
    android:title="@string/action_discard_notes" 
    android:showAsAction="always" 
    android:orderInCategory="1"/> 

回答

1

您需要設置ActionModeCallback EDITTEXT的所以CAB中止,並呼籲FrameLayout里長的像點擊下面的代碼...

m_editText.setCustomSelectionActionModeCallback(new Callback() 
      { 

       @Override 
       public boolean onCreateActionMode(android.view.ActionMode p_mode, Menu p_menu) 
       { 
        return false; 
       } 
       @Override 
       public boolean onPrepareActionMode(android.view.ActionMode p_mode, Menu p_menu) 
       {     
        return false; 
       } 

       @Override 
       public void onDestroyActionMode(android.view.ActionMode p_mode) 
       { 
       } 

       @Override 
       public boolean onActionItemClicked(android.view.ActionMode p_mode, MenuItem p_item) 
       { 
        return false; 
       } 
      }); 

您需要返回false在onCreateActionMode用於中止CAB(上下文操作欄)。

相關問題