Making a basic redirect function

  • Replies:2
Derek Hill
  • Forum posts: 2

Jun 13, 2016, 2:56:24 AM via Website

im trying to make a function to make directing with intent more smooth.

so instead of this

[code]
public void gotoPage(View view){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
[/code]

i want it something like this

protected void gotopg(String tgtlnk){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}

calling this way....gotopg(MainActivity) so when i call it its a simply 1 line to go to another activity.

I am new to this and java was never my strong suit but i do have php experience.

i want to be able to call this function send a variable which would be the target to go to.

i also dont understand why there is a View view. could someone elaborate this a bit more. im really confused.

Reply
Derek Hill
  • Forum posts: 2

Jun 15, 2016, 8:13:05 AM via Website

nothing??

Reply
Vladimir S.
  • Forum posts: 266

Jun 15, 2016, 11:52:19 AM via Website

Hi Derek,

public void gotoPage(View view)

View-class parameter is used when you set gotoPage() as onClick method for some View element of layout (such as button, image, text, etc) for example:

<Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="gotoPage"
            android:text="Button"/>

In this case variable "view" will content the Button-object with id "btn1"

If you don't use gotoPage() as onClick method, you can set any other parameters.

Reply