Wednesday, January 22, 2020


Code to navigate from one activity to other in Android

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btn"
        android:text="Press Here"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.755" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:text="Button 1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.654" />
</androidx.constraintlayout.widget.ConstraintLayout>
 

MainActivity.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button=(Button)findViewById(R.id.btn);
        Button button1=(Button)findViewById(R.id.btn1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(MainActivity.this,Activity2.class);
                startActivity(i);

            }
        });
    }
}

Activity2.java
package com.example.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.widget.Button;

public class Activity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        Button bt=(Button)findViewById(R.id.btn3);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(Activity2.this, Activity.class);
                startActivity(i);
            }
        });
    }

}

activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".Activity2Fragment"
    tools:showIn="@layout/activity_2">

    <Button
        android:id="@+id/btn3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="Back Button"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

2 comments:

  1. Benefits of studying medicine in Georgia
    The Georgia is one of the fast growing country. It is also a popular destination for those who want to do a medical degree abroad. The country offers a good environment to study and stay. The medicine degree offered at the best colleges is valued across the world with students from all over coming to study here. This is why doing Georgian National University is a good option for Indian students.
    Why study medicine in Georgia?
    There are many benefits of studying MBBS in Georgia. These benefits explain why you should consider Georgia as a destination if you want to do MBBS abroad:
    1) The Georgia is a popular destination for medicine students not just from India but from across the world, including the USA, UK, and Germany.
    2) The medical colleges in the Georgia like the Georgian National University follow the American system of teaching, which makes it popular.
    3) Georgia offers a safe and comfortable environment for students. The climate and the friendly people make it convenient for Indians to study here.
    4) The cost of doing MBBS in the Georgia is a great benefit. The tuition fees and living expenses are reasonable. If you want to do a medical degree at an Indian college, you need to pay huge amounts as donation. Compared to this, the cost of a degree in Georgia is reasonable.
    5) The colleges have the best infrastructure with competent faculties. This ensures the best quality education for students.
    6) The admission process is simple. NEET exam is optional and there is no requirement of any other entrance exam.
    7) After completing the course, students can take up the eligibility exam in India. This will give them the recognition for their degree, allowing them to do higher studies in India and also practice medicine. Students who do their degree in Georgia have done well in the screening exam.
    All the benefits listed above would have helped you understand why studying for an MBBS degree in the Georgia is a good decision for Indian students. It is economical and you get a quality degree that is recognized in India.

    ReplyDelete