I have two layouts: main.xml and journal.xml
When I click on a button in the main.xml layout, the journal.xml layout will be opened.
The problem is that i would like to create a back button which will re-open the main.xml layout.
When I try to do:
ImageButton buttonHome = (ImageButton)findViewById(R.id.image);
The image is not found because she is not in my main.xml
Could you please help me.
Thanks
Here is the code:
public class MDPI_1Activity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.journal);
ImageButton buttonJournal = (ImageButton)findViewById(R.id.imageButton1); //Journal
ImageButton buttonHome = (ImageButton)findViewById(R.id.image); //Journal
buttonJournal.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
setContentView(R.layout.journal);
}
});
buttonHome.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
setContentView(R.layout.main);
}
});
}
}
The “imageButton1” is in my main.xml file and works good but the “image” is in my second xml file named “journal” and does not exist in the R file.
EDIT: I don’t know if this will work.. but you can set the onClick parameter on your layout (XML) like this: