문제

I have an application with three tabs. Under each, I'd like to be able to do things such as add buttons and/or TextViews to add functionality or show content. I have set up tabs using TabsPagerAdapter, and they all work fine. I have added button and TextView elements to the xml file for a tab, but when I try to connect them using findViewById, I get errors because the class is not an activity class.

How do I get app functionality under a tab?

도움이 되었습니까?

해결책

As @Ahmed Hafez suggested you can use your root view in your fragment or use, from your fragment as well :

getActivity().findViewById().

Both would work. The first option is a little more precise in case 2 view share the same id (which would not be a very good pactice).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top