Reputation: 521
I've just started up with ActionBarSherlock, and was please to get a styled, three tab interface laid down very similar to the demo "Tab Navigation". Next step of course is to fill those tabs with something useful. I looked into the fragment demos, particularly "tabs", and I've tried to implement that solution, but it seems much too complicated for what I'm looking for. I don't need stacking, throttling, and custom loading. I would simply like to fill each tab with a basic activity, or what I believe would previously have been considered an activity. Could anyone provide insight on setting up a simple fragment or fragment activity that loads an xml layout file and has the normal methods I'm familiar with? Am I even on the right track?
Upvotes: 2
Views: 1222
Reputation: 28063
This is the declaration of a basic SherlockFragment
public class FirstFragment extends SherlockFragment {
Button button;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_fragment, null, false);
button = v.findViewById(R.id.button);
button.setOnClickListener(....);
return v;
}
}
You can notice that you have inflate the layout you want to display in the Fragment inside the onCreateView method where you can also init your layout components (for example set the onClickListener for a button).
If you'd like to understand more take a look at this page: http://developer.android.com/training/basics/fragments/index.html
Upvotes: 1