I've got this Layout:
ComposeView http://img845.imageshack.us/img845/2121/d6zp.png
The 2 borders (left,right )are filled by icons. When I touch one of these icons I access to other activity. The top black bar is a custom title bar.
The clear grey inside space is where I need to fit all activities that I've got on my app. So this layout would be something like a menu layout that would be static in all the activities.
This is the Layout xml:
menu_view.xml
<RelativeLayout
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"
tools:context="com.example.MenuView" >
<!-- Show top black custom title bar-->
<include
layout="#layout/custom_tittlebar" >
</include>
<!-- Button columns -->
<LinearLayout
android:id="#+id/lefthandmenu"
android:layout_width="85dip"
android:layout_height="match_parent"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:background="#drawable/border_cut" >
<ImageView
... />
...
</LinearLayout>
<LinearLayout
android:id="#+id/righthandmenu"
android:layout_width="85dip"
android:layout_height="match_parent"
android:layout_below="#id/title"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:background="#drawable/border_cut" >
<ImageView
... />
...
</LinearLayout>
<!-- Blank space which will contain other activities -->
<LinearLayout
android:id="#+id/activitycontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/righthandmenu"
android:layout_toRightOf="#id/lefthandmenu"
android:layout_below="#id/title"
android:orientation="vertical" >
</LinearLayout>
And this is the class where are defined all the icon's onClickListeners.
MenuView.java
public class MenuView extends RelativeLayout {
private final LayoutInflater inflater;
Context context;
public MenuViewActivity(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.menu_view, this, true);
((ImageView)this.findViewById(R.id.navButton)).setOnClickListener(launch_nav);
}
final OnClickListener launch_nav = new OnClickListener() {
#Override
public void onClick(View v) {
getContext().startActivity(new Intent(getContext(), Navigation.class));
}
};
Well, having this (I'm not sure if its all ok, maybe I'm doing something wrong with the inflate method or something like this), now the thing would be to define the other activitie's layouts to be inside this view. To do this, I write:
ExampleActivity.java
public class ExampleActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout inside_menu_view = (LinearLayout)findViewById(R.id.activitycontent);
View this_layout = getLayoutInflater().inflate(R.layout.main, inside_menu_view, true);
inside_menu_view.addView(this_layout);
But I'm getting a NullPointerException on this last line. So, something when inflating on this snippets must be wrong.
Hey use the following structure. put. include your common layout in each and every activity layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Show top black custom title bar-->
<include
android:id="#+id/ll_top"
layout="#layout/custom_tittlebar"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</include>
<include
android:id="#+id/ll_left"
layout="#layout/custom_left"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
</include>
<include
android:id="#+id/ll_right"
layout="#layout/custom_right"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" >
</include>
<Button
android:id="#+id/btn_center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="center"
android:layout_toRightOf="#+id/ll_left"
android:layout_centerHorizontal="true"
android:layout_below="#+id/ll_top"
></Button>
</RelativeLayout>
You can have one main activity like BaseActivity that is extended by FragmentActivity. Base activity extends SlidingFragmentActivity and implements basic structure like menu etc. FragmentActivity onCreate method is :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fm = getSupportFragmentManager();
//This is main content that is switchable
mContent = new MainListActivity();
//Additionally you can define those two lines as fragments and add them as default on both sides :
sideFragments = new sideFragments(this);
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, mContent);
ft.replace(R.id.side_framgments, sideFragments);
ft.commit();
}
When you press some of those buttons from your menu(left and right border) you will change the fragment in middle of the screen with this function in FragmentActivity :
public void switchContent(Fragment fragment, String tag) {
mContent = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,fragment).addToBackStack(tag).commit();
}
Note R.id.content_frame is the XML that is switchable between those two lines (let say menus on both sides) and R.id.side_framgments are those two lines in between the main layout that is switchable.
Related
The following code is trivial but simulates the problem.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="#+id/btnGoToExtra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="266dp"
android:text="Go To Extra"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
layout_extra.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btnBackToMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="186dp"
android:text="Back To Main"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btnGoToExtra)
.setOnClickListener(v -> {
setContentView(R.layout.layout_extra);
findViewById(R.id.btnBackToMain)
.setOnClickListener(vv -> {
setContentView(R.layout.activity_main);
});
});
}
}
Question
I can navigate to the layout_extra from activity_main and return to activity_main. Unfortunately, after this round trip, I can no longer be able to navigate to layout_extra anymore.
What causes this problem and how to fix it?
Explanation will follow in chat but that is not how it is supposed to be done, For views to change, You have other options like using Fragments or using new activity entirely, I would also like to suggest moving to kotlin.
public class MainActivity extends AppCompatActivity {
View mainView;
View extraView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainView = getLayoutInflater().inflate(R.layout.activity_main, null);
extraView = getLayoutInflater().inflate(R.layout.layout_extra, null);
setContentView(mainView);
mainView.findViewById(R.id.btnGoToExtra)
.setOnClickListener(v -> {
setContentView(extraView);
});
extraView.findViewById(R.id.btnBackToMain)
.setOnClickListener(vv -> {
setContentView(mainView);
});
}
}
Reading through the snippet above, here's how everything went
The line
findViewById(R.id.btnGoToExtra)
.setOnClickListener
Registers Button with id btnGoToExtra for click events and when that happens you have the nested
findViewById(R.id.btnBackToMain)
.setOnClickListener
Which registers the element with id backToMain for click events and that's all
Calling setContentView() multiple times is not recommended. The normal way to switch between layouts in the same activity is to use a ViewFlipper or FrameLayout
From here
You then have:
XML
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:src="#drawable/icon"
android:scaleType="fitCenter"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
<TextView
android:text="Learn-Android.com"
android:textSize="24sp"
android:textColor="#000000"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"/>
</FrameLayout>
code
private void SwitchLayout2() {
RelativeLayout Layout1 = (RelativeLayout)findViewById(R.id.layout1);
RelativeLayout Layout2 = (RelativeLayout)findViewById(R.id.layout2);
// Enable Layout 2 and Disable Layout 1
Layout1 .setVisibility(View.GONE);
Layout2.setVisibility(View.VISIBLE);
}
private void SwitchLayout1() {
RelativeLayout Layout1 = (RelativeLayout)findViewById(R.id.layout1);
RelativeLayout Layout2 = (RelativeLayout)findViewById(R.id.layout2);
// Enable Layout 1 & Disable Layout2
Layout1.setVisibility(View.VISIBLE);
Layout2.setVisibility(View.GONE);
}
I'm trying to figure out a good solution on how to extend EditText to allow me to have other Views layered on top. I am trying to make a custom View that is an EditText that has a TextView on top to display the number of characters, and an ImageView on top for a clear button.
Currently, I have it working with extending FrameLayout, but that doesn't give me the control/flexibility that I am looking for. Such as I can't use ButterKnife's #OnTextChanged as it expects a TextView, and I don't have direct access to any XML attributes of the EditText unless I pass them through.
Thanks for your time.
ClearableEditText.java
public class ClearableEditText extends FrameLayout {
public ClearableEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
protected void init() {
View inflate = inflate(getContext(), R.layout.clearable_edit_text, this);
ButterKnife.bind(this, inflate);
...
}
...
}
R.layout.clearable_edit_text.xml
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/clearable_edit"
style="#style/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<ImageView
android:id="#+id/clearable_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:src="#drawable/button_clear"
android:visibility="invisible"
tools:visibility="visible" />
<TextView
android:id="#+id/clearable_count"
style="#style/edit_text_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
tools:text="1200" />
</FrameLayout>
I find it simpler in these situations to use an empty layout in the xml which I later fill on runtime with whatever elements I want. example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView ..... />
<Button........./>
.
.
.
<LinearLayout
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
and in the activity
LayoutInflater inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout container = (LinearLayout)findViewById(R.id.container);
MyComplexView myComplexView = new MyComplexView(inflater, container);
where MyComplexView:
public static class MyComplexView{
LinearLayout container;
LayoutInflater inflater;
TextView textView ;
ImageView img;
EditText editText;
public MyComplexView(LinearLayout container,LayoutInflater inflater ){
this.container = container;
this.inflater = inflater;
View v = (View) inflater.inflate(R.layout.mylayout, null);
container.addView(v);
textView = (TextView)v.findViewById(R.id.textview);
img = (ImageView)v.findViewById(R.id.imgaviev);
editText = (EditText)v.findViewById(R.id.edittext);
// assign whatever text change listeners or on click listeners you want
}
public void makeEditTextMultiline(boolean flag){
if(flag){
edittext.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}
else{
edittext.setSingleLine(true);
}
}
public String getEditTextText(){
return editText.getText().toString();
}
}
After that you can create all sorts of methods in the MyComplexView class to manipulate the object.
I think it's easier this way than extending the View class.
I want to change fragments depending on button click. (I have made two fragment classes called fragmentLeft and fragmentMiddle)
This is my MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
Fragment fr;
public void selectFrag(View view) {
if(view == findViewById(R.id.bigbutton_left)) {
fr = new fragmentLeft();
}else {
fr = new fragmentMiddle();
}
FragmentManager fm = getFragmentManager();
if (fm != null) {
// Perform the FragmentTransaction to load in the list tab content.
// Using FragmentTransaction#replace will destroy any Fragments
// currently inside R.id.fragment_content and add the new Fragment
// in its place.
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_place, fr);
ft.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
This is fragmentLeft.java
public class fragmentLeft extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
//Inflate the layout for this fragment
return inflater.inflate(
R.layout.fragmentleft, container, false);
}
}
the same is for fragmenttwo with the exception of the layout id passed to infater.inflate()
I have made two layout files two, with the correct names as well .
This is the definition of my fragment from my activity_main.xml
But I am unable to get the buttons to do anything. No transactions take place, and I am stuck with the first fragment.
After a bit of googling , I came to know that its not recommended that you use fragment in the layout, but some other type of layout, but I saw this example code http://examples.javacodegeeks.com/android/core/app/fragment/android-fragments-example/
that seems to work just fine.
what is the problem ?
::EDIT::
There is something really weird going on.
If I use this layout xml file for main Activity:
<?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" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fragment No.1"
android:onClick="selectFrag" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Fragment No.2" />
<fragment
android:name="com.mainpackage.FragmentOne"
android:id="#+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The fragments change and behave as they are expected to.
But if I use this layout:
<RelativeLayout 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"
tools:context=".MainActivity" >
<Button
android:id="#+id/button2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBaseline="#+id/bigbutton_middle"
android:layout_alignBottom="#+id/bigbutton_middle"
android:layout_marginLeft="7dp"
android:layout_toRightOf="#+id/bigbutton_middle"
android:background="#drawable/mainbutton_right" />
<Button
android:id="#+id/bigbutton_left"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBaseline="#+id/bigbutton_middle"
android:layout_alignBottom="#+id/bigbutton_middle"
android:layout_marginRight="7dp"
android:layout_toLeftOf="#+id/bigbutton_middle"
android:background="#drawable/mainbutton_left" />
<Button
android:id="#+id/bigbutton_middle"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="187dp"
android:background="#drawable/mainbutton_middle" />
<fragment
android:id="#+id/fragment_place"
android:name="com.mainpackage.FragmentOne"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#+id/bigbutton_right" />
</RelativeLayout>
The fragments dont seem to change,i.e. the buttons seem to be dead.
What could be the problem ?
I am using Eclipse Juno
You are not getting a reference of the Buttons you are clicking in order for the FragmentTransaction to take place. You need to set OnClickListeners on the Buttons so they can execute relevant code.
One reason why the second layout doesn't display is because you are referencing an inexistant id:
<fragment
android:id="#+id/fragment_place"
android:name="com.mainpackage.FragmentOne"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="#+id/bigbutton_right" />
I do not see a View with an id of bigButton_right on that xml.
Another reason why the first xml works and the second doesn't is because you are not setting an onClick: property to any Button on the second xml.
Currently when running my application, going to this activity does not display my fragment. Am I adding the fragment wrong and so nothing in the fragment is displayed? Or is there something wrong the dynamic behavior in the fragment onCreateView method?
My Activity Code
public class AskQuestionActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ask_question);
}
}
My Activity XML
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/header_text"/>
<fragment android:name="com.mypackage.AskQuestionFragment"
android:id="#+id/question_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
My Fragment Code
public class AskQuestionFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String questionText = "What is your favorite color?";
List<String> answers = Arrays.asList("Red", "Blue", "Yellow");
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.question, container);
Resources res = getResources();
int id = res.getIdentifier("question_text", "id", layout.getContext().getPackageName());
TextView questionTextView = (TextView)layout.findViewById(id);
questionTextView.setText(questionText);
id = res.getIdentifier("question_answers", "id", layout.getContext().getPackageName());
RadioGroup radioGroup = (RadioGroup)layout.findViewById(id);
Collections.reverse(answers);
for (String s : answers) {
RadioButton button = new RadioButton(layout.getContext());
button.setText(s);
radioGroup.addView(button, 0);
}
return layout;
}
}
My Fragment XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/question_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/question_text"/>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/question_answers"></RadioGroup>
<Button
android:id="#+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/submit_button_text"
/>
</LinearLayout>
try to put framelayout instead of fragment in xml. and in your activity's onCreate create the instance of your fragment you want to display and add it to the fragment container
public class AskQuestionActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ask_question);
AskQuestionFragment fragment = new AskQuestionFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.id_of_your_container, fragment).commit();
}
}
Your problem might be when doing this:
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.question, container);
Consider to replace that line with one of the following:
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.question, null);
or
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.question, container, false);
change your layout from linear to be framelayout, and attach your fragment in activity .
getSupportFragmentManager().beginTransaction()
.add(R.id.your_fragment_container, fragment).commit();
I'm starting to build a simple Android app so when I press my video button it calls a fragment which contains the video player, but I'm always getting: No view found for id 0x7f090005...
I wonder if you give me a hand by figuring out what is wrong in the code that I'm writing.
Here is my MainActivity.java file:
public class MainActivity extends Activity {
private Button mVideoButton;
Fragment fragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mVideoButton = (Button)findViewById(R.id.videoButton);
// Video Button
mVideoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FragmentVideo sf = new FragmentVideo();
ft.add(R.id.fragmentVideo, sf);
ft.commit();
}
});
}
}
Then I have my main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activityStart" >
<ImageView
android:src="#drawable/armstrong_on_moon"
android:contentDescription="#string/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:layout_weight="1" />
<TableRow
android:gravity="center|bottom"
android:layout_weight="0">
<Button
android:id="#+id/videoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/video" />
</TableRow>
Next, my FragmentVideo.java class:
public class FragmentVideo extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState ){
View v = inflater.inflate(R.layout.fragment_video, parent, false);
return v;
}
}
And at last, the fragment_video.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"
android:id="#+id/fragmentVideo" >
<VideoView
android:id="#+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="#+id/prog"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center" />
</LinearLayout>
Please let me know if I'm doing something wrong or if I'm missing something as I can see where the issue lays.
Thanks very much for any help in advance.
EGMWEB
On ft.add() the int parameter refers to the container to which you want to add the Fragment; you are trying to add the Fragment to the Fragment's own layout (Android doesn't find the View because it is not inflated yet, if it did it will throw and Exception in this case; you cannot add a Fragment to its own layout). You want to replace R.id.fragmentVideo with R.id.activityStart to add the Fragment to the current TableLayout that is part of the already inflated main_activity layout
Could you check whats the equivalent view for the id '0x7f090005' in the R.java file. It should be under gen folder of your project. The framework is not able to find this under the resource file that you have in this java class.