I'm in the MainActivityFragment and want to call the activity "CountdownActivity" by pressing a button. This works.
But the try and catch returns the following exception while trying to setContentView(R.layout.activity_countdown); :
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Bellow you find my code, I think this is all whats necessary.
The new Fragment get called this way:
public void Countdown(Integer time){
Intent CountdownIntent = new Intent(getActivity(),CountdownActivity.class);
CountdownIntent.putExtra(Intent.EXTRA_TEXT, time);
startActivity(CountdownIntent);
}
activity_countdown.xml
="1.0"="utf-8"
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_countdown"
android:name="com.test.app.count.CountdownActivityFragment"
tools:layout="@layout/fragment_countdown"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
fragment_countdown.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.test.app.count.CountdownActivityFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Countdown"
android:id="@+id/TextView_showCountdownTime"/>
</FrameLayout>
CountdownActivity.class
public class CountdownActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_countdown);
}
catch (Exception e){
Log.e(CountdownActivity.class.getName(), "Exception: " + e);
}
}
}
What I have tried:
I get no error when I delete the part with fragment in activity_countdown.xml and e.g. use a RelativeLayout. But it's not what I want