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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:51:19+00:00 2026-06-15T11:51:19+00:00

So I am new to Android development, and trying to wrap my head around

  • 0

So I am new to Android development, and trying to wrap my head around the Master/Detail flow design. As such, I’m using the default classes Eclipse creates for you – so ScreenDetailActivity, ScreenDetailFragment, ScreenListActivity, and ScreenListFragment. One of my Detail fragments uses a layout that contains a series of checks and fields for entering data, and a button that is supposed to make the Activity class using the fragment pass that data to a calculator class, which then performs some basic calculations with the data. For example, found in the calculation_layout.xml file used by one of the Detail fragment in question:

<EditText android:id="@+id/edit_value"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="numberDecimal|numberSigned"
      android:hint="@string/background_value" />

<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/button_singleCalc"
    android:onClick="calculate" />

I think I have the the Button’s calculate function working (i.e. the app doesn’t crash when the calculate is empty or does trivial things); it’s implemented in both ScreenListActivity and ScreenDetailActivity, since either could be using the fragment.

However, whenever I try to access the EditText objects in the Detail fragment, the app crashes. I’m trying something like this:

public void calculate(View view){
    //Retrieve all the information, and set the values in the Calculator
    EditText editText = (EditText) findViewById(R.id.edit_value);
    String number = editText.getText().toString();
    double angle = Double.parseDouble(number);

    Calculator.longCalc();
}

And inflating the layout in my ScreenDetailFragment like this, not unlike how the default method generated by Eclipse works (where mItem is basically an instance of a little class containing information on which fragment should be displazed):

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // The returned view
        View rootView;
        // If mItem is non-null...
        if (mItem != null) {
            if (mItem.title == "Calculation") {
                // If the title is Calculation, use the calculation layout
                rootView = inflater.inflate(R.layout.calculation_layout, container, false);
            } else {
                // Otherwise, show the dummy content as text in a TextView
                rootView = inflater.inflate(R.layout.fragment_screen_detail, container, false);
                ((TextView) rootView.findViewById(R.id.screen_detail)).setText(mItem.title);
            }
        } else {
            rootView = inflater.inflate(R.layout.fragment_screen_detail, container, false);
        }

        return rootView;
    }

The result, as said earlier, is a crash.

I assume that what I am supposed to do is somehow access rootView from the Activity, but I don’t really know how to do that safely and effectively.

Can someone give me some pointers here?

UPDATE:

I have tried implementing OnClickListener, setting it up as such when that particular layout is inflated:

((Button)rootView.findViewById(R.id.button_calc)).setOnClickListener(this);

and implementing the onClick(View) function as such:

public void onClick(View view) {
        //Retrieve all the information, and set the values in the Calculator
        view = (View) view.getParent();
        EditText editText = (EditText) layout.findViewById(R.id.edit_phiD);
        String number = editText.getText().toString();

        Calculator.angle = Double.parseDouble(number) * 2.0 * Math.PI/360.0;

        Calculator.longCalc();
    }

However, the error persists. It also persists if I recast the ViewParent to a LinearLayout, a ViewGroup, or if I use view straight as is comes. To be clear, I am trying to get at the parent layout of the button that was clicked, so that I can go back down into that layout’s other child Views and access their states.

  • 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-15T11:51:20+00:00Added an answer on June 15, 2026 at 11:51 am

    You don’t need to go through your activity in order to achieve this. Remove the onclick line and add an id for the button in your layout:

    <Button android:id="@+id/calc_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="@string/button_singleCalc" />
    

    Then, simply add an OnClickListener to your button within your Fragment. Something like that:

    private View mRootView;
    private  EditText mEditText;
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // If mItem is non-null...
        if (mItem != null) {
            if (mItem.title == "Calculation") {
                // If the title is Calculation, use the calculation layout
                mRootView = inflater.inflate(R.layout.calculation_layout, container, false);
                mEditText = (EditText) mRootView.findViewById(R.id.edit_phiD);    
                ((Button)mRootView.findViewById(R.id.calc_button)).setOnClickListener(this);         
            } else {
                // Otherwise, show the dummy content as text in a TextView
                mRootView = inflater.inflate(R.layout.fragment_screen_detail, container, false);
                ((TextView) mRootView .findViewById(R.id.screen_detail)).setText(mItem.title);
            }
        } else {
            mRootView = inflater.inflate(R.layout.fragment_screen_detail, container, false);
        }
    
        return mRootView;
    }
    

    (Your fragment needs to implement OnClickListener for this). Then you’ll get a callback on your Fragment, and here’s what you do there:

    public void onClick(View v){
        //Retrieve all the information, and set the values in the Calculator
        String number = mEditText.getText().toString();
        double angle = Double.parseDouble(number);
    
        Calculator.longCalc();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Android programming and trying to wrap my head around this just
I am new to using SQLite databases and android mobile development. I am trying
I am new to android development and I've hit a hurdle when trying to
I am new to android development . I'm trying to download and run the
I'm new to Android development, i'm trying to port an IOS app to Android.
I'm new to Android development. My OS is WinXP. I'm trying to install two
I'm new to Android development and was playing around with the camera. I just
I am new to Android Development and trying to create a sample application. Can
I'm very new to Android development and just started to study. What I'm trying
hey, im new to android development and trying to make my first application. What

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.