如何在片段 android 中获取和使用小部件元素的操作
How to get & use Widget Element's Action in fragment android
我的应用程序需要一个好的 Ui 标签布局设计,我在 google 中搜索并找到了一个 UI,它使用了 View Pager 和 Action bar Tabs。
Link 是:
http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/
我下载了模板并导入到 eclipse.i 以尝试使用该模板,不知道在哪里添加我的 activity 编码。
我上传了下面的片段之一,我试图获得按钮的动作。但是 "it shows create a method finViewById".
public class MoviesFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
Button bu=(Button) findViewById(R.id.button1);
return rootView;
}
我对片段了解不多。我在 google 中进行了搜索,但无法获得与此相关的解决方案。任何人都可以帮助我如何以及在何处使用上面的 UI 模板添加我的 activity 编码。提前致谢。
使用这个
Button bu=(Button)rootView.findViewById(R.id.button1);
试试这个,
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
Button bu=(Button) rootView.findViewById(R.id.button1);
return rootView;
}
我的应用程序需要一个好的 Ui 标签布局设计,我在 google 中搜索并找到了一个 UI,它使用了 View Pager 和 Action bar Tabs。
Link 是: http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/
我下载了模板并导入到 eclipse.i 以尝试使用该模板,不知道在哪里添加我的 activity 编码。 我上传了下面的片段之一,我试图获得按钮的动作。但是 "it shows create a method finViewById".
public class MoviesFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
Button bu=(Button) findViewById(R.id.button1);
return rootView;
}
我对片段了解不多。我在 google 中进行了搜索,但无法获得与此相关的解决方案。任何人都可以帮助我如何以及在何处使用上面的 UI 模板添加我的 activity 编码。提前致谢。
使用这个
Button bu=(Button)rootView.findViewById(R.id.button1);
试试这个,
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
Button bu=(Button) rootView.findViewById(R.id.button1);
return rootView;
}