在onCreate中,我將線性佈局視圖附加到變量activeView
。然後我打電話給registerForContextMenu(activeView)
。看起來,一切工作正常,上下文菜單被創建,項目是可點擊的,但是,在onContextItemSelected
,我打電話AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo()
,我得到一個nullpointerexception。我已經追蹤了空menuInfo變量回來發現registerForContextMeu(activeView)
從一開始就傳遞OnCreateContextMenu一個空ContextMenuInfo。這是爲什麼發生?我在一個不同的視圖中執行同樣的過程,一個listView,與linearlayout一起,並且問題在那裏不存在。爲什麼registerForContextMenu傳遞onCreateContextMenu null ContextMenuInfo?
3
A
回答
0
你期望從getMenuInfo()中獲得什麼?無論如何,我不認爲它會被LinearLayout填充,我相信至多你能夠得到產生菜單的View(相同的LinearLayout)。
相關問題
- 1. onCreateContextMenu被ContextMenuInfo的null值調用
- 2. 爲什麼傳遞對象爲null?
- 3. Android傳遞值爲什麼爲null?
- 4. onCreateContextMenu
- 5. 傳遞null爲空?
- 6. onCreateContextMenu兩個列表
- 7. 使用intent傳遞HashMap會返回null,爲什麼?
- 8. 爲什麼我們將null傳遞給XMLHttpRequest.send?
- 9. registerForContextMenu不叫
- 10. JPanel作爲NULL傳遞
- 11. 角4作爲參數傳遞NULL null
- 12. 傳遞什麼?
- 13. onCreateContextMenu不被調用
- 14. 傳遞NULL值
- 15. 爲什麼int作爲Object傳遞?
- 16. 如何設置圖標onCreateContextMenu
- 17. 爲什麼〜null === -1?
- 18. 爲什麼yylval null?
- 19. 爲什麼$ db PDO對象在構造函數參數中作爲null傳遞?
- 20. 爲Gradle傳遞的參數爲null android
- 21. 爲什麼null參考打印爲「null」
- 22. 爲什麼鑄造Object(null)不爲null?
- 23. 遞歸函數在參數不爲NULL時傳遞NULL指針
- 24. 爲什麼mSuggestedFriends爲null?
- 25. getClass()。getClassLoader()爲null,爲什麼?
- 26. 爲什麼listOfFiles爲null?
- 27. JavaFX TreeView爲null爲什麼?
- 28. 爲什麼getFacesContext()變爲null
- 29. 傳遞什麼信息dispatch_queue_attr_t
- 30. 爲什麼是空?價值的傳遞有什麼問題?
如果您同時擁有'OnItemLongClickListener'和'registerForContextMenu',則必須在偵聽器中返回'false'以避免'AdapterContextMenuInfo'爲null。我實際上在監聽器中調用'registerForContextMenu',因爲我禁用了某些列表項的上下文菜單,並且它工作正常。 –
Thx @ 3k- !!花了幾個小時才找到這個解決方案。在聽衆中返回'假'就完成了這項工作! – mixable