-5

I have created a login page which consists of a username password login button and a signup button which should be a link. I want to convert this signup(text view) to a link that can be navigated to the next page. How would I do that? For example if I click on don't have an account? sigup,it should be navigated to welcome.java..

Please help....

enter image description here

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_gradient"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="40dp"
            android:text="@string/welcome"
            android:textColor="@color/white"
            android:textSize="45dp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_form_rounded"
            android:orientation="vertical" >

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:background="@null"
                android:hint="@string/email"
                android:padding="5dp"
                android:singleLine="true" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:padding="5dp" />
        </LinearLayout>

        <Button
             android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:background="@drawable/bg_button_rounded"
            android:text="@string/login"
            android:textColor="@color/white" />

    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="25dp"
        android:gravity="center_horizontal"
        android:text="@string/signup"
        android:autoLink="web" 
        android:textColor="@color/white" />


</RelativeLayout>

mainactivity.java

package com.example.internationalization12;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

        //getActionBar().hide();
    }



}
Gurfuffle
  • 784
  • 12
  • 32
user3736518
  • 75
  • 1
  • 2
  • 12

3 Answers3

1

Try this :

package com.example.internationalization12;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

TextView txtSignUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         txtSignUp=(TextView)findViewById(R.id.txt_sign_up);
         txtSignUp.setText(Html.fromHtml("<u>Dont have account?SignUp</u>")
         txtSignUp.setOnClickListener(signUpListener);
        //getActionBar().hide();
    }
    public OnClickListener signUpListener=new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
          startActivity(new Intent(MainActivity.this,Welcome.class));
        }
    };

}
Imran Betara
  • 649
  • 3
  • 8
0

you can try Linkify here

textview.setText("www.androiddeveloper.com");
Linkify.addLinks(textview, Linkify.WEB_URLS);
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
0

You have to setOnTouchListener to the TextView. Here I give you an example:

    public class MainActivity extends Activity implements View.OnTouchListener { 
      private TextView tv1; 

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

        tv1 = (TextView) findViewById(R.id.tv1); 

        tv1.setOnTouchListener(this); 

      } 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 

       // HERE YOU HAVE TO CHECK WHICH ID IS SELECTED, IF YOU HAVE MORE THAN ONE,
       //   AND WHICH EVENT HAS THE USER DONE.

      // IN YOUR CASE.. OPEN WEBSITE LIKE THIS:


Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

        return true; 
      } 
    }
Jaume Colom Ferrer
  • 334
  • 1
  • 3
  • 13
  • This one of many many ways, and also over-complicated. `onClick` would be much easier, since with your method, you still have to check motionEvent. – Marius Jul 24 '14 at 11:49
  • @Jaume Colom Ferrer thnks it worked.Can you tell me tell how can i include hover while clicking signup? – user3736518 Jul 24 '14 at 11:57