TabBookList.java
public class TabBooklist extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_booklist, container, false);
return rootView;
//error->
Button btn_test = getActivity().findFragmentById(R.id.btn_test);
//<-
}
}
tab_booklist.xml
...
tools:context="org.androidtown.mobile_termproj_0408.MainActivity$PlaceholderFragment">
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="push"
android:id="@+id/btn_test"
/>
<TextView
android:id="@+id/section_label2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="book list tab2" />
</TableRow>
The tab_booklist.xml
is created by fragment and TabBookList.java
is link with tab_booklist.xml.
I want to get button object in xml file.
I found using getActivity().findFragmentById(R.id.btn_test);
that get xml object in fragment.
But I can't do that.
How to get xml object in fragment?