PART 1 BASIC-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.viraj.petbioapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView dog;
private ImageView cat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dog = (ImageView) findViewById(R.id.id_dog);
cat = (ImageView) findViewById(R.id.id_cat);
dog.setOnClickListener(this);
cat.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.id_dog:
Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
break;
case R.id.id_cat:
Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
break;
}
}
}
PART 2-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create another bio activity single page to display either dog or either cat and its name
main activity
package com.example.viraj.petbioapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView dog;
private ImageView cat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dog = (ImageView) findViewById(R.id.id_dog);
cat = (ImageView) findViewById(R.id.id_cat);
dog.setOnClickListener(this);
cat.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.id_dog:
// Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
Intent dogintent=new Intent(getApplicationContext(),BioActivity.class);
dogintent.putExtra("key_is_name","DOG");
dogintent.putExtra("key_is_Decr","Dog is very lovely animal");
startActivity(dogintent);
break;
case R.id.id_cat:
//Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
Intent catintent = new Intent(getApplicationContext(),BioActivity.class);
catintent.putExtra("key_is_name","CAT");
catintent.putExtra("key_is_Decr","Cat is very lovely animal");
startActivity(catintent);
break;
}
}
}
create another bio activity single page to display either dog or either cat and its name
main activity
package com.example.viraj.petbioapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView dog;
private ImageView cat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dog = (ImageView) findViewById(R.id.id_dog);
cat = (ImageView) findViewById(R.id.id_cat);
dog.setOnClickListener(this);
cat.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.id_dog:
// Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
Intent dogintent=new Intent(getApplicationContext(),BioActivity.class);
dogintent.putExtra("key_is_name","DOG");
dogintent.putExtra("key_is_Decr","Dog is very lovely animal");
startActivity(dogintent);
break;
case R.id.id_cat:
//Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
Intent catintent = new Intent(getApplicationContext(),BioActivity.class);
catintent.putExtra("key_is_name","CAT");
catintent.putExtra("key_is_Decr","Cat is very lovely animal");
startActivity(catintent);
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.viraj.petbioapp.MainActivity">
<ImageView
android:id="@+id/id_dog"
android:layout_width="172dp"
android:layout_height="141dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="52dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/dogimage" />
<ImageView
android:id="@+id/id_cat"
android:layout_width="172dp"
android:layout_height="185dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="96dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_dog"
app:srcCompat="@drawable/cat" />
</android.support.constraint.ConstraintLayout>
secondpage.java////////////////////////////////////////////////////////////
package com.example.viraj.petbioapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class BioActivity extends AppCompatActivity {
private ImageView imageView_all;
private TextView txt1_name, txt2_desc;
private Bundle extras;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bio);
imageView_all = (ImageView) findViewById(R.id.id_imageall);
txt1_name = (TextView) findViewById(R.id.id_name);
txt2_desc = (TextView) findViewById(R.id.id_description);
extras=getIntent().getExtras();
if(extras!=null)
{
String name=extras.getString("key_is_name");
String desc=extras.getString("key_is_Decr");
setup(name,desc);
}
}
public void setup(String name,String desc)
{
if (name.equals("DOG"))
{
imageView_all.setImageDrawable(getDrawable(R.drawable.dogimage));
txt1_name.setText(name);
txt2_desc.setText(desc);
//we show dog stuff
}
else if(name.equals("CAT"))
{
//we show cat stuff
imageView_all.setImageDrawable(getDrawable(R.drawable.cat));
txt1_name.setText(name);
txt2_desc.setText(desc);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.viraj.petbioapp.BioActivity">
<ImageView
android:id="@+id/id_imageall"
android:layout_width="294dp"
android:layout_height="214dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.422"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/id_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="124dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_imageall" />
<TextView
android:id="@+id/id_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="84dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_name" />
</android.support.constraint.ConstraintLayout>