Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:27:55+00:00 2026-06-12T02:27:55+00:00

header.xml <LinearLayout android:layout_width=fill_parent android:layout_height=wrap_content > <TextView android:id=@+id/txtTime android:layout_width=0dip android:layout_height=fill_parent android:layout_marginRight=10dp android:layout_weight=1 android:gravity=right /> </LinearLayout>

  • 0

header.xml

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/txtTime"               
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:gravity="right" />
    </LinearLayout>

i added header.xml in all my screen layouts…

 <include
        android:id="@+id/top_header"
        layout="@layout/header" />

Now i want start timer and set text of every remaining seconds in text header txtTime…
So which screen i write code for countdown timer and set textview so all screen display time in textview..

can any one suggest me its possible to set text only one screen and display in all screen ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:27:57+00:00Added an answer on June 12, 2026 at 2:27 am

    Please try below code . It will solve your prolem.

    Follow below steps.

    1) Make one BaseActivity Class.
    2) Make One MainActivity Class and extend BaseActivity.
    3) Make another SecondActivity class and extend BaseActivity.
    

    Here i post all the classes you required .

    What i do in BaseActivity ?

    I create one Countdown Timer class called MyCount which will display
    the remaining time . I create one boolean flag which set false by
    default . so when user call setHeading() function of BaseActivity it
    will check the falg if it false then start the timer and if it is true
    then again set the timer and starts again .

    BaseActivity

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.widget.TextView;
    
    public abstract class BaseActivity extends Activity
    {
        private TextView textView = null;
        public static MyCount counter = null; 
        private static boolean flag = false;
        private static long millisUntilFinishedVariable = 0;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
    
        }
    
        protected void setHeading(String message) 
        {
            if(textView == null)
            {
                textView = (TextView)findViewById(R.id.textView);
                if(textView != null)
                    textView.setText(message);
    
                if(flag == false)
                {
                    counter = new MyCount(30000, 1000);
                    counter.start();
                }
                else
                {
                                counter.cancel();
                    counter = new MyCount(millisUntilFinishedVariable, 1000);
                    counter.start();
                }
            }
        }
    
        // countdowntimer is an abstract class, so extend it and fill in methods
        public class MyCount extends CountDownTimer
        {
    
            public MyCount(long millisInFuture, long countDownInterval) 
            {
                super(millisInFuture, countDownInterval);
            }
    
            @Override
            public void onFinish() 
            {
                textView.setText("done!");   //TextView object should be defined in onCreate
                flag = false;
            }
    
            @Override
            public void onTick(long millisUntilFinished) 
            {
                millisUntilFinishedVariable = millisUntilFinished;
                flag = true;
                textView.setText("Left:" + millisUntilFinished/1000);// This will be called every Second.
            }
        }
    } 
    

    MainActivity

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class MainActivity extends BaseActivity 
    {
        private Button buttonClick = null;
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            setHeading("Text From Main Activity"); 
    
            buttonClick = (Button)findViewById(R.id.buttonClick);
            buttonClick.setOnClickListener(new OnClickListener() 
            {
                @Override
                public void onClick(View arg0) 
                {
                    startActivityForResult(new Intent(MainActivity.this,SecondActivity.class), 0);
                }
            });
        }
    }
    

    activity_main.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" >
    
       <include layout="@layout/header"/>
    
       <Button
           android:id="@+id/buttonClick"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:layout_alignParentTop="true"
           android:layout_marginLeft="96dp"
           android:layout_marginTop="68dp"
           android:text="Second Activity" />
    
    </RelativeLayout>
    

    SecondActivity

    import android.os.Bundle;
    
    public class SecondActivity extends BaseActivity 
    {
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.second_activity);
            setHeading("From Second Activity");
        }
    }
    

    second_activity.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" >
    
       <include layout="@layout/header"/>
    
    </RelativeLayout>
    

    header.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" >
    
    
        <TextView 
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="18.0sp"/>
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?xml version=1.0 encoding=UTF-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:background=@drawable/background android:orientation=vertical > <include android:id=@+id/include1 android:layout_width=fill_parent android:layout_height=70dp
<?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/linearLayout1 android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical > <LinearLayout android:id=@+id/linearLayout2 android:layout_width=fill_parent android:layout_height=wrap_content
This is my layout: <?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=wrap_content android:orientation=vertical> <TextView android:layout_width=wrap_content
I have a header common in all activities. header.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a main activity with this layout file: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I wanted to update my layout from <?xml version=1.0 encoding=utf-8?> <TextView xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent
So my main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
I have a layout like this one: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/tabBar android:layout_width=fill_parent
I have a layout as below <?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
This is the static xml that I have: <LinearLayout android:id=@+id/LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.