Android - View How to get hosting Activity

摘要:Android - View How to get hosting Activity

當我自訂物件後,會得到Context

但自訂物件,要能夠能夠跳到另一個Activity,需要startActivity,

這時需要的是Activity物件才能呼叫startActivity方法

 

view要怎麼取得Activity呢?結果還真的有解答如下:

http://stackoverflow.com/questions/8276634/android-get-hosting-activity-from-a-view


Activity host = (Activity) view.getContext()
view.isFocused()

試過了還真的可以。