using findviewbyid in a class that does NOT extend Activity in android

前端 未结 4 645
无人及你
无人及你 2020-12-13 06:35

I have a class that is currently extending Activity and I have methods like findViewById, ArrayAdapter etc. I want to turn it into an independent class but all the above met

4条回答
  •  悲哀的现实
    2020-12-13 06:48

    findViewById is non-static public method of the Activity Class ,so it only be available for a Activity object. Therefore, import android.view.View and android.app.Activity won't make it available. To make it available, you could pass around a Actvity object - usually a this point in your activity. However, notice that you should always update your View in the UI thread.

提交回复
热议问题