Android studio Relative Layout click and go to another form - java

Viewed 264

I have a relative layout with an image and 2 texts. I need when the user presses the relative layout to go to another activity and show those texts and image in a bigger format. Is this possible? If yes how i do this? This is what i have done: https://i.stack.imgur.com/piUjZ.png

3 Answers

Yes, its possible.

Just add OnClickListener to your relative layout, and pass Intent to next activity.

1 - Give your RelativeLayout an ID

2 - Set your RelativeLayout XML to android:clickable="true"

Your final xml will be look like this:

<RelativeLayout
android:id="@+id/RelativeLayoutTest"
android:clickable="true">

3 - Then add the code in your onCreate method :

RelativeLayout relative1 = (RelativeLayout) findViewById(R.id.RelativeLayoutTest);
  relative1.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
         //you can pass image & text over here using putExtra()
        startActivity(new Intent(this, YOURCLASS.class) );
    }
});

Yes, you can do it. Take bigger TextView and ImageView and set visibility gone by default. Set onClickListener on Relative Layout by findViewById and onClick of RelativeLayout turn visibility on of both views and make gone visibility of smaller views.

set relativelayout click listener and pass all these three using

intent.putExtra("name",name[postion]);
intent.putExtra("name",image[postion]);
intent.putExtra("name",text[postion]);

and get these into your second activity and show where you want to show

Related