2017-05-24 52 views
0

我已经创建了一个Android应用程序到我的最终项目 它有一个选项卡活动与三个选项卡,在每个选项卡中有很多组件。例如,在第二个选项卡中,我有一个WebView和一个按钮,当我点击按钮时,webview必须加载一些数据。
我该如何处理代码?
在tab1activity.java是不可能的,因为mainactivity.java中也没有findViewById()这使我的应用程序崩溃 我该怎么办?如何访问标签活动中的视图?

+1

请将您的代码发布 –

回答

0

你必须让你的按钮和webview在你的tabTwo布局。而且你也必须为你的TabTwoFragment创建一个类。将此代码放到TabTwoFragment类中以访问其视图:

@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; 
}