May 5, 2021

ImageView To New Activity In Android Studio - Androidpro.in

 xml code


<?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"
    >


    <ImageView
        android:id="@+id/computer"
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:src="@drawable/computerfundamental"
        android:layout_marginTop="20dp"/>

    <ImageView
        android:id="@+id/word1"
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:src="@drawable/word"
        android:layout_below="@+id/computer"
        android:layout_marginTop="10dp"
        />

    <ImageView
        android:id="@+id/powerpointl"
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:src="@drawable/powerpoint"
        android:layout_below="@+id/word1"
        android:layout_marginTop="10dp"
        />
    <ImageView
        android:id="@+id/shorctutkey"
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:src="@drawable/shortcutekeys"
        android:layout_below="@+id/powerpointl"
        android:layout_marginTop="10dp"
        />



</LinearLayout>



Java Code

public class MainActivity extends AppCompatActivity {
ImageView computer, word, excel, powerpoint, shortcutekry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        computer =(ImageView) findViewById(R.id.computer);
        computer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), SecondActivity2.class);
                startActivity(intent);
            }
        });


        word =(ImageView) findViewById(R.id.word1);
        word.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), WordActivity.class);
                startActivity(intent);
            }
        });


        powerpoint =(ImageView) findViewById(R.id.powerpointl);
        powerpoint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), PpointActivity.class);
                startActivity(intent);
            }
        });


        shortcutekry =(ImageView) findViewById(R.id.shorctutkey);
        shortcutekry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), ShorctuteActivity.class);
                startActivity(intent);
            }
        });


    }
}


Whatsapp Button works on Mobile Device only