Twitter Facebook Delicious Digg Stumbleupon Favorites More

Saturday 12 May 2018

switch case and set on click on diffrent side

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageView catView;
    private ImageView dogView;

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

        catView = (ImageView) findViewById(R.id.catID);
        dogView = (ImageView) findViewById(R.id.dogId);

        catView.setOnClickListener(this);
        dogView.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.catID:
                //go to second activity
                Intent catIntent = new Intent(MainActivity.this, BioActivity.class);
                catIntent.putExtra("name", "Jarvis");
                catIntent.putExtra("bio", "Great cat.  Loves people and meows a lot!");
                startActivity(catIntent);
              //  Toast.makeText(MainActivity.this, "Cat", Toast.LENGTH_LONG).show();
                break;

            case R.id.dogId:
                //go to second activity
                Intent dogIntent = new Intent(MainActivity.this, BioActivity.class);
                dogIntent.putExtra("name", "Dufus");
                dogIntent.putExtra("bio", "Great Dog.  Loves people and barks and eats a lot!");
                startActivity(dogIntent);
              //  Toast.makeText(MainActivity.this, "Dog", Toast.LENGTH_LONG).show();
                break;


        }

    }
}
Share:

0 comments:

Post a Comment

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab