I'm new in the android develop world. I created simple application and created a simple GUI with one button. If the user presses this button, I want to change the screen to show some other GUI.
How can I do this?
You Perform use this code:
public class Activity1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Activity2.class);
startActivityForResult(myIntent, 0);
}
});
}
}
activity 2:
public class Activity2 extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Button next = (Button) findViewById(R.id.Button02);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}
Also Make Sure to Create 2 different xml in Layout folder and add both Activity in Manifest File like
<activity android:name=".Activity2"></activity>
Hope this will help you.
You can do something like this:
import android.view.View;
/** Called when the activity is first created. */
public class YourActivity extends Activity implements View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.your_button_id);
button.setOnClickListener(this);
}
public void onClick(View v) {
Intent intent = new Intent(your_present_activity.this, target_activity.class);
startActivity(intent);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With