156370307053 Date:-
Practical-11
Aim:-Create an application that will pass two number using TextView
to the next screen, and on the next screen display sum of that number
156370307053 Date:-
Practical-11
Aim:-Create an application that will pass two number using TextView
to the next screen, and on the next screen display sum of that number
ACTIVITY_MAIN.XML
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="36dp"
android:text="@string/Value1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_marginLeft="33dp"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="phone" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems="10"
android:inputType="phone" >
156370307053 Date:-
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="@string/Addition" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="48dp"
android:text="@string/Value2"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
ACTIVITY2_MAIN.XML
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity2" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="38dp"
android:layout_marginTop="28dp"
android:text="@string/v1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
156370307053 Date:-
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="22dp"
android:text="@string/v2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="24dp"
android:text="@string/add"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
[Link]
package [Link].pr11;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button button=(Button)findViewById([Link].button1);
[Link](this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link], menu);
return true;
}
156370307053 Date:-
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(this,[Link]);
EditText t1=(EditText)findViewById([Link].editText1);
EditText t2=(EditText)findViewById([Link].editText2);
String s1=[Link]().toString();
String s2=[Link]().toString();
[Link]("t1",s1);
[Link]("t2",s2);
startActivity(i);
}
}
[Link]
package [Link].pr11;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main_activity2);
Intent i=getIntent();
String s1=[Link]("t1");
TextView tv1=(TextView)findViewById([Link].textView1);
[Link]("value1 :"+s1);
String s2=[Link]("t2");
TextView tv2=(TextView)findViewById([Link].textView2);
[Link]("value2 :"+s2);
final int a=[Link](s1);
final int b=[Link](s2);
int sum = a+b;
TextView tv3=(TextView)findViewById([Link].textView3);
[Link]("Addition is :"+[Link](sum));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].main_activity2, menu);
return true;
}
}
156370307053 Date:-
OUTPUT:-