What I want to do is that when I click a button ( BtnA or BtnB) , the fragment just below buttons is replaced by corresponding fragment (FragmentA or FragmentB).
this is my code in MainActivity.java
#Override
public void onClick(View v) {
Fragment replacableFragment = new Fragment();
switch (v.getId()){
case R.id.button1:
{
replacableFragment = new Fragment_One();
Log.d("OnClick","button1");
break;
}
case R.id.button2:
{
replacableFragment = new Fragment_Two();
Log.d("OnClick","button2");
break;
}
}
FragmentManager manager= getFragmentManager();
Log.d("OnClick","1");
FragmentTransaction transaction = manager.beginTransaction();
Log.d("OnClick","2");
transaction.add(R.id.fragmentPlace, replacableFragment);
//transaction.addToBackStack(null);
Log.d("OnClick","3");
transaction.commit();
}
and this is my code of Fragment_One.java
public class Fragment_One extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_one,container,false);
}
}
Fragment_Two.java is the same with 'inflater.inflater(R.layout.fragment_two,container,false);'
When I click any button, logcat shows everything exactly. But Fragment is not replaced at all.
I think my code has no problem to function it.
Can anyone know about this?
xml files for my project are below:
activity_main.xml
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FRAGMENT ONE"
android:id="#+id/button1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FRAGMENT TWO"
android:id="#+id/button2"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragmentPlace"
android:name="lkm.com.practical5_3.Fragment_One"/>
fragment_one.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:background="#android:color/holo_orange_dark"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="THIS IS FRAGMENT ONE"
android:id="#+id/text1"/>
</LinearLayout>
fragment_two.xml
The same one as 'fragment_one.xml'
use this
transaction.replace(R.id.fragmentPlace, replacableFragment).commit();
I want to anser my question!
The problem was the container!
At activiy_main.xml, the container of the fragment ais defined as 'fragment ~/'.
I fix it as 'FrameLayout ~/' and it was succesfful!
Thank you!
Related
In one of my fragment class, it has two buttons (A and B) on top, used to switch to another fragment when clicked using viewPager.
When buttonA is clicked, it should switch to page A and so on.
When I click button A, how can I make the text in A show below the two buttons?
fragment_menu.xml
<?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">
<Button
android:id="#+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:padding="15dp"
android:text="ButtonA"
android:textSize="12sp" />
<Button
android:id="#+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:layout_toRightOf="#+id/buttonB"
android:backgroundTint="#color/materialGrey600"
android:padding="15dp"
android:text="ButtonB"
android:textSize="12sp" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
MenuFragment
public class MenuFragment extends BaseFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_menu, container, false);
final ViewPager viewPager = (ViewPager) v.findViewById(R.id.pager);
viewPager.setAdapter(new ViewPagerAdapter(getActivity().getFragmentManager()));
Button btnA = (Button) v.findViewById(R.id.buttonA);
Button btnB = (Button) v.findViewById(R.id.buttonB);
btnA.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewPager.setCurrentItem(0, true);
}
});
btnB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
viewPager.setCurrentItem(1, true);
}
});
return v;
}
}
ViewPagerAdapter
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position)
{
case 0:
return new A()
case 1:
return new B()
}
return null;
}
#Override
public int getCount() {
return 2;
}
}
Output
try with below code.hope it is helpful for you ;)
P.S. You just need to set button style as you want :)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_above="#id/llButton"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/llButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp">
<Button
android:id="#+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="15dp"
android:text="ButtonA"
android:textSize="12sp" />
<Button
android:id="#+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:backgroundTint="#color/colorAccent"
android:padding="15dp"
android:text="ButtonB"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
Since you are using Relative Layout you can add layout_below
<androidx.viewpager.widget.ViewPager
android:layout_below="#id/buttonB"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
you are doing it wrong, You cannot align a button to itself. That's why your buttons are not working properly. In your button B do this:
android:layout_toRightOf="#+id/buttonA"
instead of this:
android:layout_toRightOf="#+id/buttonB"
And to your viewPager add "android:layout_below:"
<androidx.viewpager.widget.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/buttonA" />
You have to set your layout like this....
[I think you want something like this 2 button fisrt and then viewpager for change the content ][1]
[1]: https://i.stack.imgur.com/dluXA.png
**Code for main Page **
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="5dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:padding="10dp"
android:layout_marginTop="10dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<Button
android:id="#+id/btn_donner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#drawable/rect_outline"
android:text="Donor's"
android:textAlignment="center"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_blood_bank"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Blood Bank"
android:background="#drawable/rect_outline"
android:layout_weight="2"
android:textAlignment="gravity"
android:textColor="#color/white" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
Code For Java File of two Buttons And ViewPager
//Click Event for donor's and blood bank .....
View.OnClickListener listener = new View.OnClickListener() {
#Override
public void onClick(View view) {
Fragment fragment = null;
if (view == view.findViewById(R.id.btn_donner))
{
fragment = new TabDonnerFragment();
}
else
{
fragment = new TabBloodBankFragment();
}
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_content, fragment);
transaction.commit();
}
};
btn_donner.setOnClickListener(listener);
btn_blood_bank.setOnClickListener(listener);
return root;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fragment fragment = null;
fragment = new TabDonnerFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_content, fragment);
transaction.commit();
}
}
I'm new to Android and recently created a dashboard for my app. I followed a tutorial but it only covered the front end. I created a layout called content_main.xml with three Cardviews. Each of these Cardviews contains the code
android:clickable="true"
Beginning the back end of things, I created a java receiver class called DashboardActivity (as seen below). I want to make my Cardviews clickable so that when one is clicked, I am taken to another screen within my app. The other screens in my app I am trying to get to are fragments. Each of these screens has its own java class in my "Fragments" folder. One of them, of which I try calling on in the code that follows is called SettingsViewFragment().
So far, I have tried the following. It does nothing.
public class DashboardActivity extends AppCompatActivity {
CardView cd1, cd2, cd3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
cd1 = (CardView) findViewById(R.id.dash_settings);
cd2 = (CardView) findViewById(R.id.dash_profile);
cd3 = (CardView) findViewById(R.id.dash_activity);
cd1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragment1 = new SettingsViewFragment();
}
});
}
}
UPDATE: FULL CODE
public class DashboardActivity extends AppCompatActivity {
CardView cd1, cd2, cd3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
cd1 = findViewById(R.id.dash_settings);
cd2 = findViewById(R.id.dash_profile);
cd3 = findViewById(R.id.dash_activity);
cd1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("Testing 123 123 123");
}
});
}
}
And my XML: (it continues for 3 cards this way)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.newproject.DashboardActivity"
tools:showIn="#layout/toolbar">
<FrameLayout
android:id="#+id/dashframe"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/dash_settings"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/bg_circle1"
android:src="#drawable/ic_settingspicture"
android:padding="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="View your settings"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Follow along with guided tutorials"
android:padding="5dp"
android:textColor="#android:color/darker_gray"/>
</LinearLayout>
Replace
Fragment fragment1 = new SettingsViewFragment();
With this
Fragment fragment1 = new SettingsViewFragment();
FragmentTransaction fragmentTransaction=getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.Main_Layout,fragment1);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Change Fragment fragment1 = new SettingsViewFragment (); by Toast.makeText (mActivity, "onCLick", Toast.LENGTH_LONG) .show ();
//if show toast The problem is not the onClick, the problem is when loading the fragment
Fragments should be instantiated with the newInstance() static method.
cd1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment settingsFragment = SettingsFragment.newInstance();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.contentView, settingsFragment);
fragmentTransaction.commit();
}
});
In the SettingsFragment
public static SettingsFragment newInstance() {
return new SettingsFragment();
}
XML for content_main
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/dash_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/dash_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/dash_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
</android.support.v7.widget.CardView>
<FrameLayout
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
</FrameLayout>
</LinearLayout>
This will transact the fragment into the FrameLayout that is positioned below the CardViews. Now this is probably not ideal, you would most likely want to launch a new activity that will host the fragment but this should work. Unless this is already in some Activity that hosts the fragment. But the key code is in the onClick.
I have looked for several times, but I think no one is facing the same issue that I'm facing right now. I have the following fragment:
FRAGMENT XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
RecyclerView XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAlignment="center"
/>
</LinearLayout>
FRAGMENT JAVA CODE SNIPPET
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View viewRoot = inflater.inflate(R.layout.fragment_xml, container, false);
recyclerView = (RecyclerView) viewRoot.findViewById(R.id.recyclerview_id);
recyclerView.setOnTouchListener(new OnSwipeTouchListener(getActivity()) {
#Override
public void onSwipeRight() {
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
ft.replace(R.id.frameLayout, new Fragment2()).commit();
}
});
So, what I'm doing on the code above is adding a touch listener, so when the user swipe from right to left, the fragment goes to the other fragment (Fragment2)
This works perfectly fine! However... I need to add onClickListener inside my recyclerAdapter, so I can catch the click listener of each item. And here comes the problem... When adding a click listener, the swipe listener does not work. It seems that the listener of the click "overrides" my listener of the swipe. The question is. How to add both on the recyclerview, and make them work together?
In fragment A, it has listView. When the list is clicked, it should pass the data to fragment B.
A.java
B fragment2 = new B();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment1, fragment2);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
B.java
public class B extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.b, container, false);
Log.d("TAG","fragment2");
return view;
}
}
a.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/some_text"
android:textSize="20sp" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</FrameLayout>
b.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="false">
<AbsoluteLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="218dp"
android:layout_height="47dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Update Page"
android:id="#+id/textView114"
android:layout_x="12dp"
android:layout_y="20dp" />
</AbsoluteLayout>
</ScrollView>
This is how my Fragment A looked like.
When the list is clicked.
What's wrong here :?
in your a.xml use the following :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/app_name"
android:textSize="20sp" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</FrameLayout>
I think may be your problem in instantiating the EditText fields, you'd better declare your items after the view is created, so you have to override the method onViewCreated and make your declarations in it, then put your database work in a try-catch block to make sure it isn't the reason of any problems:
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
name3 = (EditText) view.findViewById(R.id.editText9);
date3 = (EditText) view.findViewById(R.id.editText12);
Bundle bundle = this.getArguments();
date = bundle.getString("date1");
ID = bundle.getString("ID");
RetrievePage(date, ID);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.b, container, false);
return view;
}
public void RetrievePage(String date, String id) {
final String date2 = date;
final String id2 = id;
Log.d("m", id2);
name3.setText("Lim ");
date3.setText(date2);
try {
database = dbHelper.getWritableDatabase();
c = database
.rawQuery(
"SELECT i.Weather FROM Information i LEFT JOIN WorkForce w ON w.TInfo_id = i._id WHERE i.Name = ? AND i._id= ? ",
new String[] { String.valueOf("Lim"),
String.valueOf(id2) }, null);
if (c != null) {
while (c.moveToNext()) {
Info I = new Info();
Force WF = new Force();
String Weather = c.getString(c
.getColumnIndexOrThrow(MyDatabaseHelper.Weather));
}
}
c.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
About fragments overlapping, you must declare each fragment as a separated fragment, and the main FragmentActivity is the activity that holds the fragments which in your case must be an empty activity with only the ViewPager or FrameLayout that contain fragments:
<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"
android:background="#drawable/bg" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ac_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9" />
</RelativeLayout>
So, you must have MainActivity that contains two fragments FragmentA and FragmentB
for reference look at this answer.
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.