How To Provide Support For Fragments And Actionbar For App Which Supports Android 2.2+ Devices?
I have visited so many similar links like this i.e 1, 2 followed various examples / links i.e. this one and this one mainly I have followed this post from Vogella that too multipl
Solution 1:
All your code is look good , just keep in mind that you have two xml file activity_main.xml one will be in layout folder and second will be in layout-port folder.
For complete working demo of Vogella check out this link project.
http://www.sendspace.com/file/vdhx6w
Solution 2:
This is how i do it :
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.Button;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
publicclassMainPoPextendsSherlockFragmentActivityimplementsListFragment.OnMainMenuListener{
Button home;
Button about;
Button donate;
Button explore;
ActionBar actionbar;
ListFragment mainMenu;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransactionft= getSupportFragmentManager().beginTransaction();
mainMenu = newListFragment();
ft.add(R.id.mainView, mainMenu).addToBackStack(null).commit();
}
}
THis is how i am making a fragment and its working just fine. Try using the OnCreateView method to inflate your fragment like this in the class which is extending Fragment or is the particular fragment which you want to set some layout:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Viewv= inflater.inflate(R.layout.about_fragment, container, false);
return v;
}
Post a Comment for "How To Provide Support For Fragments And Actionbar For App Which Supports Android 2.2+ Devices?"