我想使用Square的砂漿和流量如何將引用傳遞給ActionBarDrawerToggle的Activity?
的問題是:ActionBarDrawerToggle
從支持-V7需要擁有對活動
然而view.getContext()
返回PathContext
,所以我得到一個參考
ClassCastException: flow.path.PathContext cannot be cast to android.app.Activity
那麼我如何獲得活動的參考?
我想使用Square的砂漿和流量如何將引用傳遞給ActionBarDrawerToggle的Activity?
的問題是:ActionBarDrawerToggle
從支持-V7需要擁有對活動
然而view.getContext()
返回PathContext
,所以我得到一個參考
ClassCastException: flow.path.PathContext cannot be cast to android.app.Activity
那麼我如何獲得活動的參考?
您是否嘗試使用ContextWrapper
的getBaseContext()
方法PathContext
的超類?
感謝您的回答。 Спасибо!我設法找到我這樣的活動:((PathContext)ctx).getBaseContext()。getBaseContext()。getBaseContext()。getBaseContext()但它看起來不是很好的解決方案;( –
@KorniltsevAnatoly我的答案有官方的Google文檔閱讀文檔如果你正在使用'Activity',你所需要的就是'This' –
@JaredBurrows我沒有使用活動或片段,我已經更新了我的問題以提到它 –
[什麼是Android中的上下文?]可能的重複(http://stackoverflow.com/questions/3572463/what-is-context-in-android) –
@JaredBurrows不,它不是重複的。 –