Hey there,
I'm trying to make a button for my app, which will bring the screen to another page. However, I'm not successful in doing so.
I've tried many things, without a reliefing answer.
My project doesn't accept "Intent" in my program.
My button I need to open a new layout is called "OptionButton"
Here's what I've got:
in MainActivity.java
In the beginning I got this
MainActivity.java
further I got this
MainActivity.java
And my code for my button is this
I added this in AndroidManifest:
and this in the 2nd class (java file in src map)
I got 2 classes in src map:
-Background2.java
-MainActivity.java
Also 2 layout xml's:
- activity_main.xml
- activity main2.xml
In Activity_main, I got this for the button:
Still it's not working. What am I missing?
Ty all so much!
I'm trying to make a button for my app, which will bring the screen to another page. However, I'm not successful in doing so.
I've tried many things, without a reliefing answer.
My project doesn't accept "Intent" in my program.
My button I need to open a new layout is called "OptionButton"
Here's what I've got:
in MainActivity.java
In the beginning I got this
public class MainActivity extends Activity {
private Button startButton;
private Button pauseButton;
private Button resetButton;
public Button OptionButton;
MainActivity.java
further I got this
I'm just mentioning this because I use savedInstanceState here too@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
MainActivity.java
And my code for my button is this
OptionButton = (Button) findViewById(R.id.Button1);
OptionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myClick(v); /* my method to call new intent or activity */
}
public void myClick(View v) {
Intent intent = new Intent(this, Background2.class);
startActivity(intent);// for calling the activity
}
});
I added this in AndroidManifest:
<activity android:name=".Background2"></activity>
and this in the 2nd class (java file in src map)
_(package & imports, then this:
public class Background2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
I got 2 classes in src map:
-Background2.java
-MainActivity.java
Also 2 layout xml's:
- activity_main.xml
- activity main2.xml
In Activity_main, I got this for the button:
<Button
android:id="@+id/Button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/OptionButtonLabel"/>
Still it's not working. What am I missing?
Ty all so much!
!