I'm trying to use Fragments in android.
So in the method "getItem()" into the class "TabAdapter", I have:
public Fragment getItem(int position) {
switch (position) {
case 0:
Browse tab1 = new Browse();
return tab1;
case 1:
Create tab2 = new Create();
return tab2;
default:
return null;
}
}
So, in class "Browse", I use inflate to put into TabLayout fragment, the layout that I want to use:
public class Browse extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_browse, container, false);
return rootView;
}
And in this class, a inner class that has the method "onCreate()"
public class BrowseInner extends AppCompatActivity{
DBManager db = new DBManager(this);
DBManager.DatabaseHelper dbh = new DBManager.DatabaseHelper(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("TRYTOSTAMP");
setContentView(R.layout.activity_browse);
Cursor cursor = dbh.giveAllItemFromDB();
... //"and all the logics to interact with layout"...
}
But, in this way, I have only the layout in the Fragment TabLayout, as it is defined in .xml design, but I can't interact whit it (query not processed, so fields in the layout not fill, an event on button not called and so on...) Where am I doing wrong? Thanks in advance.