OK I\'m new to android dev\'s and Java, so I\'m having problems with on click method here\'s my code. I know I\'ve gotta be close, thanks in advance. All I want my button to
Use something like this :
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.droidnova.android.splashscreen.MyApp"));
}
It would be helpful to know what code you are trying to execute when the button is pressed. You've got the onClick property set in your xml file to a method called setLogin. For clarity, I'd delete this line android:onClick="setLogin"
and call the method directly from inside your onClick()
method.
Also you can't just set the display to a new XML, you need to start a new activity with an Intent, a method something like this would be appropriate
private void setLogin() {
Intent i = new Intent(currentActivity.this, newActivity.class);
startActivty(i);
}
Then set the new Activity to have the new layout.
this will sort it for you
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but1=(Button)findViewById(R.id.button1);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent int1= new Intent(MainActivity.this,xxactivity.class);
startActivity(int1);
}
});
}
You just need to amend the xxactivity to the name of your second activity