Reputation: 155
I would like to click a save button and go to a different layout file(layout_save). I got an error message on the Button.on Click Listener() and says that con not be resolve to a type.
Here is my codes;
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_project);
Button buttonOne = (Button) findViewById(R.id.button1);
buttonOne.setOnClickListener(new Button.onClickListener(){
public void onClick(view v){
setContentView(R.layout.layout_save);
}
});
Upvotes: 2
Views: 572
Reputation: 1990
You may want to try creating an Intent i = new Intent(this, ActivityThatSaves.class)
where this is whatever activity you are on and ActivityThatSaves is whatever activity that is tied to your XML layout that you want to display. Then, call startActivity(i)
Upvotes: 0
Reputation: 808
You don't have to specify the instance of the onclicklistener inside the setOnClickListener method. All you need to do is just instantiate a new on click listener like this.
buttonOne.setOnClickListener(new OnClickListener(){
public void onClick(View v){
setContentView(R.layout.layout_save);
}
});
The onclicklistner already knows what instance it is from the set method.
Upvotes: 1