Can not find a View with findViewById()

前端 未结 4 1750
执笔经年
执笔经年 2020-11-22 12:19

I cannot find a TextView by calling findViewById(), even though the ID does exist.

OtherActivity:

public class         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 13:13

    You have to make sure that your TextView element is already generated on the creation of your activity.

    Most likely, if it's a Menu element, you will have to call the findViewById method on the onCreateOptionsMenu() callback and not on the Oncreate() callback.

提交回复
热议问题