- Code: Select all
package anritsu.futuretechnologies.connectivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Connectivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button backbutton1 = (Button)findViewById(R.id.button_back1);
Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener()
{
public void onClick(View viewParam)
{
setContentView(R.layout.menupoint1);
}
});
backbutton1.setOnClickListener(new OnClickListener()
{
public void onClick(View viewParam)
{
setContentView(R.layout.main);
}
});
}
}
Now the problem is that I get no errors, but when I try to run it I get an error in the emulator that the activity closed unexpectedly.
This only happens when I try to have two buttons working from the buttonname.setOnClickListener
If I remove one of them and just have one button used it works fine... I don't see what's wrong since I get no errors. Is it because it's under the same oncreate or something? You have it the same way in yours, but perhaps it's because they load a new xml layout file each when they are pushed?
I have main.xml and a menupoint1.xml, the idea is that pressing a button in the main.xml will take the user to the menupoint1.xml layout, and with a back button in menupoint1.xml it should take the user back to main.xml, basically I am just trying to get my head around getting buttons to work.
Or perhaps the error is in the (View viewParam), I am not that sharp with java yet and this might refer to a parameter in the main.xml and when the listener tries to listen on a button that's in a different layout file it messes up?
Anyway, if you could like really cut it out in paper for me, I would be very appreciative.



