Interface Problem

Put your problem here if it does not fit any of the other categories.

Interface Problem

Postby sojo » Tue May 12, 2009 2:51 pm

Hi,
I wanted to ask,...
If you have two interfaces and button in one of these interfaces.
* how to I use this button to go to the other interface?
* how to I return to the previous interface?
Please Help....
Thanks
sojo
Developer
Developer
 
Posts: 35
Joined: Sat Apr 25, 2009 2:06 am

Top

Postby PI9 » Tue May 12, 2009 3:55 pm

Hi,

You've just to create as many layout xml files as interfaces. All those files must have to be in the layout folder of your project.

Then,

when you implements the click listener on your button, write :
" this.setContentView(R.layout.the-name-of-the-layout-you-want-to-access); "

To return to the previous interface, you've to use the same process (this.setContentView(R.layout.the-previous-interface); ).

I hope I was clear! I can post a sample code if you need more information... :)
PI9
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Apr 06, 2009 8:40 am

Postby sojo » Tue May 12, 2009 5:31 pm

PI9
Thank you very much ....
We hope to offer us an example of this ..... :?:
sojo
Developer
Developer
 
Posts: 35
Joined: Sat Apr 25, 2009 2:06 am

Postby PI9 » Wed May 13, 2009 8:10 am

Then, here is a sample code about your interface problem. Actually it's a very simple Hello World I did few mont ago.. hope it will help!


package com.google.android.test;


import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.view.View.OnLongClickListener;



public class Hello_World extends Activity {
/** Called when the activity is first created. **/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.main);
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(Hello_World.this, "Hello World, I'm Android!", Toast.LENGTH_LONG).show();
}
});
button.setOnLongClickListener(new OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
Toast.makeText(Hello_World.this, "Bleep Bloop", Toast.LENGTH_SHORT).show();
return false;
}
});


}



private static final int MENU_INFO = 0;
private static final int MENU_QUIT = 1;

/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_INFO, 0, "Information").setIcon(R.drawable.info);
menu.add(0, MENU_QUIT, 0, "Quit").setIcon(R.drawable.quit_icon);
return true;
}

/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_INFO:
info();
return true;
case MENU_QUIT:
quit();
return true;
}
return false;
}

private void quit()
{
super.onDestroy();
this.finish();
}

private void info()
{
this.setContentView(R.layout.info);
final Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
back();
}
});
}

private void back()
{
this.setContentView(R.layout.main);
}

}
[/syntax]


Of curse, I used 2 xml layout files: main.xml and info.xml
PI9
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Apr 06, 2009 8:40 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 24 guests