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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:51:26+00:00 2026-05-26T15:51:26+00:00

There are three problems I am facing: When I click(+)button, the edit boxes are

  • 0

There are three problems I am facing:

  1. When I click(+)button, the edit boxes are going underneath the button, whereas i want them to be displayed above.
    currently displaying:

Want like this:

 <edit text1> <edit text2>
  <edit text3> <edit text4>
  <edit text5> <edit text6>
  <edit text7> <edit text8>

  <button>      <button2>
  1. As you can see, I tried parsing the edit text value which i got from the xml, into the docalc() function, and displaying the value in textbox. but its not working out. showing me nothing.
    1. can I parse values in dostuff, if yes how will i inter-relate those in docalc?

Thanks in advance…

Java Code:

import android.app.Activity;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

    public class PlusbuttonActivity extends Activity 
    implements OnClickListener  {

        TextView tt;
        TextView j;
        EditText amount1;
        EditText amount2;
        double x=0;
        double y=0;
        double a=0;
        double z=0;
        double b=0;
        Button btnButton;
        /** Called when the activity is first created. */
        private LinearLayout root;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            // modified
            amount1=(EditText)findViewById(R.id.edittext1);
            amount2=(EditText)findViewById(R.id.edittext2);
            // modified 

            View btnButton =(Button) findViewById(R.id.button_next);
            Button mButton = (Button) findViewById(R.id.button);
            mButton.setGravity(Gravity.CENTER);

             tt=(TextView)findViewById(R.id.tt);
             j=(TextView)findViewById(R.id.j);

             root = (LinearLayout) findViewById(R.id.linearLayout);
             mButton.setOnClickListener(this);
        }

            @Override
            public void onClick(View v) {
              switch (v.getId()) {
                 case R.id.button:
                 View view = doStuff();
                  addViewToRoot(view);
                break;
                 case R.id.button_next:
                     View view1 = doCalc();
                     addViewToRoot(view1);
                     break;

              }
            }

          private View doCalc() {
                // TODO Auto-generated method stub
              x=Double.parseDouble(amount1.getText().toString());
              y=Double.parseDouble(amount2.getText().toString());
              z=(x*703);
              tt.setText(Double.toString(z));
              return tt;
            }

        private View doStuff() {  
                EditText t = new EditText(PlusbuttonActivity.this);
                t.setGravity(Gravity.LEFT);
                t.setWidth(250);
                EditText a = new EditText(PlusbuttonActivity.this);
                a.setGravity(Gravity.RIGHT);
                a.setWidth(250);
                LinearLayout l = new LinearLayout(PlusbuttonActivity.this);

                t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                // t.setBackgroundColor(0xffCECECE);


                a.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

                l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

                l.addView(t);
                l.addView(a); 

                return l; 


        }          

        private void addViewToRoot(View v){
          root.addView(v);
        }

    }

xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:orientation="vertical"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:id="@+id/linearLayout">


    <LinearLayout 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                 >

            <TextView  
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:gravity="left"
                android:layout_weight="1"
                android:text="Units"
                android:id="@+id/Units"
                />
            <TextView android:layout_height="wrap_content" 
            android:gravity="right" 
            android:layout_width="wrap_content" 
            android:layout_weight="1" 
            android:text="Grades"
            android:id="@+id/j"></TextView>
        </LinearLayout>
    <LinearLayout android:id="@+id/LinearLayout01" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:orientation="horizontal">

              <EditText 
                android:layout_width="250px"     
                android:layout_height="wrap_content"    
                android:id="@+id/edittext1">
              </EditText>

              <EditText     
                android:layout_height="wrap_content"    
                android:id="@+id/edittext2" android:layout_width="150dp">
               </EditText>
        </LinearLayout>

    <LinearLayout android:id="@+id/LinearLayout01" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:orientation="horizontal">

              <EditText 
                android:layout_width="250px"     
                android:layout_height="wrap_content"    
                android:id="@+id/edittext3">
              </EditText>

              <EditText     
                android:layout_height="wrap_content"    
                android:id="@+id/edittext4" android:layout_width="150dp">
               </EditText>
        </LinearLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

        <Button android:layout_height="wrap_content" 
        android:gravity="center" android:id="@+id/button" android:text="+" android:layout_width="wrap_content"></Button>

    <Button
    android:id="@+id/button_next"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentRight="true"
    android:text="CALCULATE"
    >
    </Button>
    </RelativeLayout>
<TextView android:text="TextView" 
android:id="@+id/tt" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"></TextView>



    </LinearLayout>
  • 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-05-26T15:51:27+00:00Added an answer on May 26, 2026 at 3:51 pm

    First, set your LinearLayout’s id to something other than main. Like root. Main is the name of the xml file containing your layout, not the id of the LinearLayout item.

    Second, Instead of using this in the constructor for the EditText, use PlusbuttonActivity.this. So change the line you use to create the EditText to this:

    EditText t = new EditText(PlusbuttonActivity.this);
    

    You have to do this because when you’re in the onClick method your technically in the OnClickListener class, and this refers to the OnClickListener object. By using PlusbuttonActivity.this you’re clarifying that you mean the PlusbuttonActivity object that you’re currently in, not the OnClickListener.

    Third, to address the other issue, you can’t reference root from you anonymous OnClickListener class. Instead of calling root.addView(t), you can extract that out to a method. Putting it all together we get this:

    import android.app.Activity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    
    public class PlusbuttonActivity extends Activity {
        /** Called when the activity is first created. */
        LinearLayout root;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
        Button mButton = (Button) findViewById(R.id.button1);
        root = (LinearLayout) findViewById(R.id.root);
        mButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText t = new EditText(PlusbuttonActivity.this);
                t.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                addViewToRoot(t);
            } 
        });
    
        }
    
        private void addViewToRoot(View v){
          root.addView(v);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few problems with my mod_rewrite rules. There a three different url
I have a HTML radio button inside a repeater. I'm facing two problems: When
I'm working with Eclipse and ClearCase and we're facing the problem that there's no
When facing the problem of validating a property in a JSF2 application there are
Are there any problems converting a Visual Foxpro 6 application to Visual Foxpro 9;
I currently have the DatePicker in my project but there are problems due to
I have a problem with sorting NSTableColumn contents. In my NSTableView there are three
Hopefully the answer is no, but are there any problems with using Request.Params instead
Are there any inherent problems with calling an ole object from tsql? I have
Would there be any problems calling an HTTPS page (e.g. a credit card authorisation

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.