Reputation: 866
I have an app where user can change the content of the layout by pressing a button but when i want to replace a layout i get error in replacement line:
This is addtotry.xml
code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="150px"
android:layout_height="fill_parent"
android:background="#e7e7e7"
android:id="@+id/linearLayout">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="adrese"
android:id="@+id/adreseButton"
android:layout_below="@+id/infoButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="350px"
android:layout_toRightOf="@+id/linearLayout"
android:layout_toEndOf="@+id/linearLayout"
android:id="@+id/imageLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="350px"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/imageview"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/linearLayout"
android:layout_toEndOf="@+id/linearLayout"
android:layout_below="@+id/imageLayout"
android:id="@+id/fragment_container">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Text"
android:id="@+id/textView7"/>
</RelativeLayout>
</RelativeLayout>
This is MainActivity
:
public class MainActivity extends FragmentActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addtotry);
Button btnLoad = (Button) findViewById(R.id.adreseButton);
btnLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentVieta fh = new FragmentVieta();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, fh);
ft.commit();
}
});
}
}
I do not now where i have made mistake because i have created FragmentView and it extends fragment. Do you have any idea how to fix my problem which is shown in picture? Because i changed to (int, com.wunderlist.slidinglayersample) and it said expression needed.
Upvotes: 0
Views: 852
Reputation: 1811
Check whether your FragmentVieta
extends android.app.Fragment or support one ?
As you are using getFragmentManager()
the FragmentVieta
must extend from android.app.Fragment
only.
Upvotes: 1