-1

I'm a beginner with Android development and want to create a simple onClick event to bring me to a blank activity page. I have named my new activity page InsurancePage and added a button called insurance to my xml file. When I click on this button I want to to bring me to the InsurancePage.

<Button
            android:id="@+id/insurance"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="46.24"
            android:background="@drawable/curvebutton"
            android:lines="1"
            android:text="@string/insurance"
            android:textColor="#ffffff"
            android:onClick="onClickbtnInsurance" />
Craig Gallagher
  • 235
  • 1
  • 5
  • 19
  • I'm **100%** sure that you could find an answer to this question simply by searching. Let alone all the duplicates that would have popped up when writing the question. – Luke Joshua Park Nov 07 '15 at 21:27
  • Yea I have come across a lot of answers however as I said "I'm a beginner" and some of the answers are way over my head I just need a simple way of doing it to get me started. Thanks – Craig Gallagher Nov 07 '15 at 21:29
  • Your ability at Android Programming doesn't change how you would go about solving this problem... Look at `startActivity` and learn from there. – Luke Joshua Park Nov 07 '15 at 21:31

2 Answers2

2

To add on click event to button you can look at the next link: how to add button click event in android studio or android eclipse button OnClick event

To start new activity on button click you can look at the next link: How to start new activity on button click
Next, you can just search in Google before :)

Community
  • 1
  • 1
Evyatar Elmaliah
  • 634
  • 1
  • 8
  • 23
1

Let's say that you have a button called myButton and this is in you MainActivity class:

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

    Button myButton = findViewById(R.id.new_button);
    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, InsurancePage.class));
        }

    }

You can read more about activities here : http://developer.android.com/training/basics/firstapp/starting-activity.html

Noy
  • 116
  • 1
  • 10