0

I would like to add button to link to another activity on RegisterActivity with the following code

    public void setOnAccountCreationFirstViewListener(OnAccountCreationFirstViewListener listener) {
        mListener = listener;
    }

    /**
     * Interface for listeners of {@link AccountCreationFirstView} 
     * see {@link AccountCreationFirstView#setOnAccountCreationFirstViewListener}
     */
    public interface OnAccountCreationFirstViewListener {
        /**
         * User asked to create the account
         */
        /**
         * User asked to edit : he has an existing account
         */
        void onEditAccountRequested();
    }
}

Can anyone please help me adding a button to activity called RegisterActivity the button id is button2

Andy G
  • 19,232
  • 5
  • 47
  • 69
lainard
  • 19
  • 6
  • Question not understandable. Please add little more details. What is this code about? – Vishal Vijay Aug 26 '13 at 11:31
  • possible duplicate of [How to start new activity on button click](http://stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click) – Mario Kutlev Aug 26 '13 at 11:46

3 Answers3

1

change your button's xml and add android:onClick="openActivity" e.g.

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="openActivity"
    android:text="@string/button" />

then add this function to the Activity class whose layout contains button1

public void openActivity(View view) 
{
    Intent intent = new Intent(this, RegisterActivity .class);
    startActivity(intent);
}
Kinaan Khan Sherwani
  • 1,504
  • 16
  • 28
0

You can set the OnClickListener to the the button you want to add action. Then start the intent to go to anther activity.

button2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(getApplicationContext(),
                            RegisterActivity.class);
                    startActivity(i);
                }
            });
Seblis
  • 339
  • 4
  • 17
Ye Lin Aung
  • 11,234
  • 8
  • 45
  • 51
0

Try to understand the code and do modify your code like this.
Here I'm opening SecondActivity from FirstActivity
FirstActivity.java

Button button2;
onCreate(...){
   super(...);
   setContentView(...);
   button2=(Button)findViewById(R.id.button2);
   button2.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(getApplicationContext,
                          SecondActivity.class);
                  startActivity(i);
              }
          });
}

AndroidManifest.xml

<application ....>
 <activity name=".FisrtActivity">
<intent-filter>
    ...
</intent-filter>
 </activity>
<activity name=".SecondActivity"/>
</application>
Vishal Vijay
  • 2,518
  • 2
  • 23
  • 45