Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the following layout for the screen to input numbers. Name the file first.xml.</p> <p> </p> <pre><code> &lt;TextView android:id="@+id/firstnumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Input Ist:" android:textSize="20px" android:textStyle="bold" /&gt; &lt;EditText android:id="@+id/first" android:layout_height="wrap_content" android:layout_width="250px" /&gt; &lt;TextView android:id="@+id/secondnumber" android:text = "Input 2nd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20px" android:textStyle="bold" /&gt; &lt;EditText android:id="@+id/second" android:layout_height="wrap_content" android:layout_width="250px" /&gt; &lt;Button android:id="@+id/add_button" android:text="Add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15px" android:layout_centerHorizontal="true" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>To add these numbers</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first); Button add = (Button) findViewById(R.id.add); add.setOnClickListener(this); EditText num1 = (EditText)findViewById(R.id.first); EditText num2 = (EditText)findViewById(R.id.second); } </code></pre> <p>The click listener code </p> <pre><code>public void onClick(View v) { int n1 = Integer.parseInt(num1.getText().toString()); int n2 = Integer.parseInt(num2.getText().toString()); int result = n1 + n2; String res = Integer.toString(result); Intent intent = new Intent(getApplicationContext(), Result.class); intent.putExtra("result", result); //Passing the result to the second activity using intent startActivity(intent); } </code></pre> <p>In the Result.java class. </p> <pre><code>public class Result extends Activity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.result); Intent intent = getIntent(); String result = intent.getStringExtra("result"); TextView t1 = (TextView)findViewById(R.id.result); t1.setText(result); } } </code></pre> <p>Hope this helps..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload