I don't get my fragment to work... :-(
My Activity:
public class Test extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setTitle(R.string.title);
// actionBar.setDisplayShowTitleEnabled(false);
//
actionBar.setDisplayShowHomeEnabled(false);
Tab tab = actionBar.newTab().setText(dayName(Calendar.MONDAY))
.setTabListener(new WeekDayTabListener(getApplicationContext()));
actionBar.addTab(tab);
...
tab = actionBar.newTab().setText(dayName(Calendar.SUNDAY))
.setTabListener(new WeekDayTabListener(getApplicationContext()));
actionBar.addTab(tab);
}
public static class WeekDayTabListener implements TabListener {
private Context context;
public WeekDayTabListener(Context context) {
this.context = context;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Tools.longToast(tab.getText().toString(), this.context);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
}
my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/weekDayFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
class="com.test.fragment.DayFragment" >
</fragment>
</LinearLayout>
and finally my Fragment:
import com.actionbarsherlock.app.SherlockFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class DayFragment extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Context c = getActivity().getApplicationContext();
LinearLayout l = new LinearLayout(c);
TextView tv = new TextView(c);
tv.setText("foo");
l.addView(tv);
return l;
}
}
If I execute, I get the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.fragment/com.test.fragment.Test}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
So if i comment out the parte there is no error - but the path is correct, so what am i doing wrong?