Search code examples
javaandroidandroid-tabactivity

how to access views in tab activity?


I've created an android application to my final project it has a tab activity with three tabs, within each tab there are a lot of components. For example, in the second tab I have a WebView and a button and, when I click the button, the webview must load some data.
How can I handle the code?
In the tab1activity.java is not possible because there is no findViewById() also in mainactivity.java that's make my app crashed what can I do?


Solution

  • public class animal_tab1 extends Fragment {
    
        Button AddDiseases, ViewData;
        EditText name, laxan, upay, news;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Get the view from fragmenttab1.xml
            View view = inflater.inflate(R.layout.animal_tab1, container, false);
    
    
            Button AddDiseases = (Button) view.findViewById(R.id.btnAdd);
            Button ViewData = (Button) view.findViewById(R.id.btnView);
    
        name = (EditText) view.findViewById(R.id.ed_name);
        laxan = (EditText)view.findViewById(R.id.ed_laxan);
        upay = (EditText)view.findViewById(R.id.ed_upay);
        news = (EditText)view.findViewById(R.id.ed_News);
       }
    }