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

  • Home
  • SEARCH
  • 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 8123135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:04:33+00:00 2026-06-06T06:04:33+00:00

Does anybody know how to programmatically set the text of a button? thing is

  • 0

Does anybody know how to programmatically set the text of a button?

thing is i’m not calling this from the main layout(setContentView) i’m calling it in a view thats inflated after an asynctask
heres what i have tried but this is giving a null pointer exception on the 2nd line

Button mButton=(Button)findViewById(R.id.contact);
        mButton.setText("number");

heres my layout where i am calling the button

   <Button
       android:id="@+id/contact"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_below="@+id/address"
       android:layout_toLeftOf="@+id/badge"
       android:background="@drawable/ic_btn_call"
       android:textSize="10dp"
       android:textStyle="bold"
       android:textColor="@color/white"/>

here my view i’m inflating

ClubInfo = LayoutInflater.from(getBaseContext()).inflate(R.layout.clubinfocell,
                null);

        TextView TeamNameText = (TextView) ClubInfo.findViewById(R.id.TeamName);
        TeamNameText.setText(teamName);

        TextView AddressText = (TextView) ClubInfo.findViewById(R.id.address);
        AddressText.setText(address1);



        Button mButton=(Button)ClubInfo.findViewById(R.id.contact);
        mButton.setText(telephone);
  • 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-06T06:04:35+00:00Added an answer on June 6, 2026 at 6:04 am

    Then use your view’s object to initialize it:

    Button mButton = (Button)your_view_object.findViewById(R.id.contact);
    mButton.setText("number");
    

    When you try to identify a view other than your Activity’s layout, you have to pass the reference of that view like this. If not Android will keep looking for this element from the layout which you provided in the setContentView().

    For example, consider you have inflated a view like this:

    View View = mInflater.inflate(R.layout.gridelement, null);
    

    Then use this View’s object for the Button present in that inflated layout:

      Button mButton = (Button)View.findViewById(R.id.contact);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know how to programmatically enlarge a flex 3 button's hitArea. Is there
Does anybody know how to programmatically disable the keyboard individual letter pop-up? (This blue
Does anybody know how to generate .mht file programmatically in C#, with embedded images
Does anybody know whether one exists? I've been googling this for monthes... Thanks
Does anybody know if there is a way to display the text value of
Does anybody know a way to enable response character set selection by client for
Does anybody know how I can programmatically check (using C#) whether my program will
Does anybody know whether this can be achieved in jQuery. Target/addClass to the last
Does anybody know how to programmatically update the content of any of the standard
Does anybody know a way to create a keyboard shortcut for the button 'Expand

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.