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 8314851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:57:46+00:00 2026-06-08T20:57:46+00:00

I have a fragment that is a timer that I can add anywhere. In

  • 0

I have a fragment that is a “timer” that I can add anywhere. In the fragment I change a textView programatically, and it runs beautifully. My problem is when it comes to using a view from the layout inflated by the constructor(? Not sure if that’s the right terminology) in another method below it.

public class Timer_fragment extends android.support.v4.app.Fragment {
    int testpins;
    String testedpin;
    TextView text;  
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.timer_frag, container, false);

    TextView text = (TextView) v.findViewById(R.id.pwd_status);
    text.setText("Setting text in fragment not main");
    /* set the TextView's text, click listeners, etc. */
    updateStatus();
    return v;
}

All of that code works with no errors but when I try to add this method:

private void updateStatus() {
            TextView text = (TextView) findViewById(R.id.pwd_status);
            testPin();

            text.setText(testedpin);                         
        }

I get a red line under findViewById saying The method findViewById(int) is undefined for the type Timer_fragment.

I thought about inflating the view in all of my methods and not returning them, but surely that would affect performance somehow right?

Just tried inflating the layout before using the view but I get an error on the word inflater and container saying that they can’t be resolved.

Am I going about this correctly?

  • 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-08T20:57:48+00:00Added an answer on June 8, 2026 at 8:57 pm

    You already have a member variable in the scope of your Fragment called text. Don’t re-declare it in your methods, just assign it.

    text = (TextView) v.findViewById(R.id.pwd_status);
    

    and

    private void upateStatus() {
            testPin();
            text.setText(testedpin);                         
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this sample : I have make my own Fragment that holds tabhost and
I have class that extend FragmentActivity in it I add fragment to layout as
I'm using Android-support-v4 I have a PagerAdapter that displays a list fragment in each
I have a problem with memory allocation using malloc. Here is a fragment from
I know that when you're first instantiating a fragment you can pass arguments using
I have fragment that on a component click pop-ups DialogFragment. This dialog fragment holds
I have a Fragment that has contains lots of info (article) with a tabhost
I have a fragment that I need to display on the screen. I want
I have a simple little code fragment that is frustrating me: HashSet<long> groupUIDs =
I have a BaseFragment so called LeaderboardFragment that extends Fragment : public class LeaderboardFragment

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.