MainActivity.class
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText e1,e2;
TextView t1,t2;
Button b1;
String s1,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1=(EditText)findViewById(R.id.edttext1);
e2=(EditText)findViewById(R.id.edttext2);
b1=(Button)findViewById(R.id.button);
t1=(TextView)findViewById(R.id.txt1);
t2=(TextView)findViewById(R.id.txt2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s1=e1.getText().toString();
s2=e2.getText().toString();
t1.setText(s1);
t2.setText(s2);
if (s1.equals(s2)){
Toast.makeText(getApplicationContext(),"Your Result is Done.",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Your Result is not properly Done",Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edttext1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:hint="enter the value" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edttext2"
android:layout_below="@+id/edttext1"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/edttext1"
android:hint="enter the value" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pass to"
android:id="@+id/button"
android:layout_below="@+id/edttext2"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/txt1"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txt2"
android:layout_below="@+id/txt1"
android:layout_alignParentStart="true" />
</RelativeLayout>
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText e1,e2;
TextView t1,t2;
Button b1;
String s1,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1=(EditText)findViewById(R.id.edttext1);
e2=(EditText)findViewById(R.id.edttext2);
b1=(Button)findViewById(R.id.button);
t1=(TextView)findViewById(R.id.txt1);
t2=(TextView)findViewById(R.id.txt2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s1=e1.getText().toString();
s2=e2.getText().toString();
t1.setText(s1);
t2.setText(s2);
if (s1.equals(s2)){
Toast.makeText(getApplicationContext(),"Your Result is Done.",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Your Result is not properly Done",Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edttext1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:hint="enter the value" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edttext2"
android:layout_below="@+id/edttext1"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/edttext1"
android:hint="enter the value" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pass to"
android:id="@+id/button"
android:layout_below="@+id/edttext2"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/txt1"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txt2"
android:layout_below="@+id/txt1"
android:layout_alignParentStart="true" />
</RelativeLayout>


No comments:
Post a Comment