Update a TextView in a ViewPager from anohter Fragment - java

I have created a Tabbed Activity with 3 fragments. How can I update the text of a TextView in a Fragment from the MainActivity Java File?
TabStatus.java:
package com.sanderjochems.bluetoothdata;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TabStatus extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_status, container, false);
}
}
fragment_status.xml
<android.support.constraint.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:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sanderjochems.bluetoothdata.MainActivity"
tools:layout_editor_absoluteY="81dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="24dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_bluetooth"
android:textAllCaps="false"
android:textColor="#color/colorPrimaryText"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<TextView
android:id="#+id/tbMacAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text_mac_address" />
<TextView
android:id="#+id/tbState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text_state" />
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
I want to update the TextView tbState. How can I do that?
I tried to use a LayoutInflater, but that didnt work.
I used this piece of code for that:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layoutStatus = inflater.inflate(R.layout.fragment_status, null);
tvCurrentState = (TextView) layoutStatus.findViewById(R.id.tbState);
Regards,
Sander Jochems

Follow the documentation for communicating between fragments.

use event bus and fire the event when you perform an action in your fragment and catch that event in another fragment and update the desired textview.
follow this very simple library implementation and use
https://github.com/greenrobot/EventBus

Related

I want to add stopwatch in a fragment but the app crashes on clicking the image buttons. how to resolve?

I wanted to add Stopwatch in a fragment with bottom navigation activity. I got no error at all but the app crashes on onclicking the image buttons I have created for start pause and reset. Please Help!
package com.example.chatapp;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Chronometer;
import android.widget.ImageButton;
public class StopwatchFragment extends Fragment {
private boolean running;
private long pauseoffset;
private Chronometer chronometer;
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable
Bundle savedInstanceState ){
View view = inflater.inflate(R.layout.fragment_stopwatch, null);
chronometer = view.findViewById(R.id.cm);
return view;
}
public void startcm (View view){
if (!running){
chronometer.setBase(SystemClock.elapsedRealtime() - pauseoffset);
chronometer.start();
running = true;
}
}
public void pausecm (View view){
if (running){
chronometer.stop();
pauseoffset = SystemClock.elapsedRealtime() - chronometer.getBase();
running = false;
}
}
public void resetcm (View view){
chronometer.setBase(SystemClock.elapsedRealtime());
pauseoffset = 0;
}
}
This is my java code of that fragment. Android Studio shows no error in this.
But here in my xml code of that fragment. In front of onclick it shows
cannot resolve symbol name "startcm"
cannot resolve symbol name "pausecm"
cannot resolve symbol name "restartcm"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".StopwatchFragment">
<TextView
android:id="#+id/text_stopwatch"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_stopwatch"
android:fontFamily="#font/bold"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center_horizontal" />
<Chronometer
android:id="#+id/cm"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="68dp"
android:fontFamily="#font/bold"
android:textSize="60sp"
android:textColor="#color/colorPrimary"
android:textAlignment="center"/>
<ImageButton
android:id="#+id/start"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_play_arrow_black_24dp"
android:background="#drawable/circular_button"
android:tint="#fff"
android:layout_marginTop="175dp"
android:layout_marginLeft="50dp"
android:onClick="startcm"/>
<TextView
android:id="#+id/text_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:layout_marginTop="225dp"
android:layout_marginLeft="60dp"
android:textColor="#color/black"
android:fontFamily="#font/regular"
/>
<ImageButton
android:id="#+id/pause"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_pause_black_24dp"
android:background="#drawable/circular_button"
android:tint="#fff"
android:layout_marginTop="175dp"
android:layout_marginLeft="150dp"
android:onClick="pausecm"/>
<TextView
android:id="#+id/text_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pause"
android:layout_marginTop="225dp"
android:layout_marginLeft="157dp"
android:textColor="#color/black"
android:fontFamily="#font/regular"
/>
<ImageButton
android:id="#+id/reset"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/restart"
android:background="#drawable/circular_button"
android:tint="#fff"
android:layout_marginTop="175dp"
android:layout_marginLeft="250dp"
android:onClick="resetcm"/>
<TextView
android:id="#+id/text_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/reset"
android:layout_marginTop="225dp"
android:layout_marginLeft="258dp"
android:textColor="#color/black"
android:fontFamily="#font/regular"
/>
</RelativeLayout>
Please Help!!!
The xml onClick tag looks for your functions in your Activity, not in your fragment. Probably 3 solutions:
Move these functions to your Activity
Add view.findViewById(R.id.cmstart).setOnClickListener() to your fragment, and remove the xml tag.
You might can add a reference to your fragment in the xml tag, but I don't know how by heart.

Android Fragment in Fragment inflate error

I am new to Android development. An Fragment problem that a Fragment layout in another Fragment cannot be shown. I used almost one week on solution seeking...
If I inflate "fragment_main2" from MainFragment.java, it failed to run. But if I inflate "fragment_checker.xml", it is fine. Any advise, thanks a lot!
The structure is showing as below:
MainActivity.java (Create and show the MainFragment)
package a3.webchecker;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
public class MainActivity extends AppCompatActivity {
public StringBuilder log = new StringBuilder("Web Checker Log:\n");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main2);
Fragment fragment = new MainFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
}
}
MainFragment.java (Inflate fragment_main2.xml)
package a3.webchecker;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class MainFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main2, container, false);
return view;
}
}
activity_main.xml (Contain a FrameLayout container)
<?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="match_parent"
android:padding="8dp"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
fragment_main2.xml (contain Fragment tab & layout is using fragmentChecker.xml)
<?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="match_parent"
android:orientation="vertical"
tools:context=".MainFragment">
<fragment
android:id="#+id/web_checker_1"
android:name="a3.webchecker.CheckerFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
tools:layout="#layout/fragment_checker" />
<Button
android:id="#+id/view_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Log" />
</LinearLayout>
fragment_checker.xml (Layout)
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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"
app:cardUseCompatPadding="true"
app:contentPadding="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:context=".CheckerFragment">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="URL:"
app:layout_constraintBaseline_toBaselineOf="#+id/url"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status: "
app:layout_constraintBaseline_toBaselineOf="#+id/status"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/url" />
<Button
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Check"
app:layout_constraintEnd_toStartOf="#+id/go_to"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/status" />
<Button
android:id="#+id/go_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/check"
app:layout_constraintTop_toTopOf="#+id/check" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
In "fragment_main2.xml", you no correct to set your activity in tools:context
Repair to become this
tools:context=".MainActivity"
And because you implement fragment transaction, you have to define layout fragment in your activity.
<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="match_parent"
android:padding="8dp"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="[your fragment location]"
android:id="#+id/fragment_container" />
</LinearLayout>

videoview not showing on device nor xml design,

I am new in java and xml programming, i am making tabbed activity with fragment, there is no error when running or debug the code but VideoView is not showing, i am using Android Studio,
the idea is i want to make tabbed activity, with textView and videoview in fragment as a content that scrollable(possible ?),one more thing is the API level somehow have influence ? my phone still on KitKat
here is the (fragment) code :
package com.panduanberwudhu;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
public class MencuciTangan extends Fragment {
private VideoView player;
private String videopath;
private MediaController mediacon;
public View rootView;
//#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.mencucitangan_layout, container, false);
mediacon = new MediaController(getActivity());
player = (VideoView) rootView.findViewById(R.id.videoplayer);
videopath = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.washhand;
player.setVideoURI(Uri.parse(videopath));
player.setMediaController(mediacon);
mediacon.setAnchorView(player);
player.start();
return rootView;
//return inflater.inflate(R.layout.mencucitangan_layout,container,false);
}
}
and the layout code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mencucitangan_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.panduanberwudhu.MencuciTangan">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
/>
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/videoplayer"
android:layout_gravity="bottom"
/>
</LinearLayout>
</ScrollView>
Use this layout, where the height Relativelayout is wrap_content which will increase/wrap according to content because it is inside the ScrollView .
I removed Linearlayout as hard coded some value:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mencucitangan_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:id="#+id/ap"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<VideoView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:foregroundGravity="center"
android:id="#+id/videoplayer" />
</RelativeLayout>
</ScrollView>
Output:

Change to Activity from Fragment

I'm new to Android programming. I have the question, that how i can intent from fragment to an activity.
I was trying to code it, but i failed :( ('l_places' is the layout of Fragment Places, and 'p_tr_fr' is a clickable TableRow)
Here's my code of the Fragment:
package com.fragment.toactivity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Places extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.l_places, container, false);//l_places is the layout
return rootView;
}
public void goToAttract(View v)
{
if (v.getId()== R.id.p_tr_fr) {
Intent intent = new Intent(getActivity(), Listact.class);
startActivity(intent);
}
}
public View onCreateView(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
};
}
and here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffd4d4d4">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView2" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#ffffffff">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_gravity="bottom"
style="#android:style/Widget.AutoCompleteTextView"
android:layout_margin="0dp"
android:id="#+id/p_tr_fr"
android:onClick="onClick">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/imageView2"
android:src="#drawable/m_pf"
android:scaleType="fitCenter"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/s_shop"
android:id="#+id/textView3"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#ff000000"
android:layout_marginLeft="6dp" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
When I click on the TableRow, the app stops. Please help!
(sorry for my english)
do like this,
Intent myIntent = new Intent(getActivity(), BookmarkActivity.class);
getActivity().startActivity(myIntent);
#NAP code should work fine. If app stops - give us the stack trace?
Possible reason is that your activity is not declared in AndroidManifest.
you should have something like
<activity android:name="yourpackage.Listact" />
between <application> tag

Unable to Load Fragment from Main Activity

I am trying to load a frame on the Onclicklistener of a Button in the main activity. In my view I have written all the code correctly of main activity and fragment that requires to attach a fragment to activity. But something seems off. Appreciate any thoughts or suggestions.
I have used this link as a reference.
Below are the code details.
MainActivity.java
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends FragmentActivity {
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final android.app.ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Button btnLoad = (Button) findViewById(R.id.Button01);
OnClickListener listener = new OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
AboutFragment mAboutFragment = new AboutFragment();
fragmentTransaction.add(R.id.fragment_container, mAboutFragment,"About");
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransaction.commit();
}
};
btnLoad.setOnClickListener(listener);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_about"
android:minHeight="92dp"
android:layout_marginTop="40dp"
android:layout_marginLeft="40dp"
android:textSize="22sp"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_report"
android:id="#+id/Button02"
android:minHeight="92dp"
android:textSize="22sp"
android:layout_marginTop="40dp"
android:layout_marginLeft="80dp"
android:layout_toRightOf="#+id/Button01"></Button>
</RelativeLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
AboutFragement.jave
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AboutFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.about_fragment_main, container, false);
return view;
}
}
about_fragement_main.xml
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TextView android:id="#+id/about_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:paddingTop="30px"
android:text="header text"
android:textStyle="bold|italic"/>
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="text here" />
<TextView android:id="#+id/about_textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="zariya mission"
android:textStyle="bold|italic"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingTop="10px"
android:text="text here" />
<TextView android:id="#+id/about_textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="zariya vision"
android:textStyle="bold|italic"/>
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingTop="10px"
android:text="text here" />
<TextView android:id="#+id/about_textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="zariya values"
android:textStyle="bold|italic"/>
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingTop="10px"
android:text="sometezt." />
</LinearLayout>
The error is in the main XML file.
You root is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
But then the first child have the height fill_parent this makes the first child take all the space of the LinearLayout so when you try to put your fragment in the container, it wont appear in the screen.
Instead try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
Try to get used to use match_parent instead of fill_parent :)

Categories

Resources