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