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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:15:04+00:00 2026-06-15T20:15:04+00:00

I am porting Activity-type app to Fragments-type app. I am a bit confused where

  • 0

I am porting Activity-type app to Fragments-type app. I am a bit confused where I am supposed to initiate UI elements of the fragment.

For example, if I initiate a button from Fragment class in FragmentActivity class, I get no error.

    btnOne = (Button) findViewById(R.id.btn_one);

But, if I try to initiate onClick listener, then I get error of type java.lang.NullPointerException.

Then again, I cannot find method findViewById in the Fragment class.

Am I really forced to initiate in FragmentActivity and to specify listeners in Fragment?

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

    You initiate your button in the fragment usually. An example would be:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View fragmentView = inflater.inflate(R.layout.yourlayout, container, false);
    
            Button yourbutton = (Button) fragmentView.findViewById(R.id.button);
            yourbutton.setOnClickListener(new View.OnClickListener(){
    
                   @Override
                   public void onClick(View v) {
                         //Do your thing
                   }
            }
    
            return fragmentView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my existing app I am porting two activities to fragments. The case is
I am trying to send the events from one Java class to Activity. Scenario
Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
We're porting a legacy Java app to JRuby and would like to reuse some
I'm porting an existing app to rails that makes extensive use of stylized anchors
I'm porting the T6963-based LCD driver from AVR-GCC to the microchip C18 compiler. I
I am currently porting an application from iOS into Android and I have ran
I'm porting my game from WP7 to Android. My game is a kind of
I've been slowly porting my iOS App to Android so I can take my

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.