Java Part :
package first.learn.passingdatabetweenactivities;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText etName;
Button btnSimpleString;
TextView textTwo,
textOne;
void add (int a, int b){
int c = a+b;
textTwo.setText(""+c);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textTwo = (TextView)findViewById(R.id.textTwo);
add (10, 20);
etName = (EditText) findViewById(R.id.etName);
btnSimpleString = (Button) findViewById(R.id.btnSimpleString);
}
}
Xml Part :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp">
<TextView
android:hint="Text One... "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textOne"/>
<TextView
android:hint="Text two... "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textTwo"/>
<EditText
android:layout_marginTop="25dp"
android:hint="write...."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etName"/>
<Button
android:id="@+id/btnSimpleString"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple String"/>
</LinearLayout>
No comments:
Post a Comment