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?
how to access views in tab activity?
108 views Asked by esamaldin elzain At
2
There are 2 answers
0
On
You must be having your button and webview in your tabTwo layout. And also you must be having a class for your TabTwoFragment as well. Put this code in your TabTwoFragment class to access its views:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_two_layout, parent, false);
WebView webView = (WebView) rootView.findViewById(R.id.your_web_view);
Button button = (Button) rootView.findViewById(R.id.your_button);
// Set Your clicklistener on your button here.
return rootView;
}