I am working on a school project and I need to start multiple activities with buttons (4 to be exact). I have an idea but it works for one button, when I try to implement the second button to start the activity I get lot of errors. Later I read that I can't use multiple onClick(View) in one activity. Anyway, here is my idea, I think I know why it does not work, but I have nothing else, and I can't find nothing in my books.
MainActivity.java
package com.example.skvik.unit_conv;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity implements View.OnClickListener {
Button getVolt, getamp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
this.setUpUI();
}
private void setUpUI() {
this.getVolt = (Button) findViewById(R.id.volt);
this.getVolt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent explicitIntent = new Intent();
explicitIntent.setClass(getApplicationContext(), Napon.class);
this.startActivity(explicitIntent);
}
private void setUpUI() {
this.getamp = (Button) findViewById(R.id.amp);
this.getamp.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent explicitIntent = new Intent();
explicitIntent.setClass(getApplicationContext(), struja.class);
this.startActivity(explicitIntent);
}
}
Any idea will help :) This is my idea for two buttons, and I know this will not cut it, but I hit a dead end. Thanks for the help.