I am thinking, how to set up the new window in Android after pressed button. I have the first window, when I have a few buttons. After pressed one of these buttons (for example on the button for adding new name) I want to show new window, when will be only Edit text for new name...
Any ideas, how is possible to do or where to search inspiration?
Thanks a lot,
Manny
You need to start new activity.
Intent i = new Intent(ActualActivity.this,ActivityB.class);
String name = "example"
i.putExtra("NAME", name);
startActivityForResult(i, ID);//or startActivity,see javadoc for your preferences
With "startActivity" or "startActivityForResult" you call the new activity. For that you need to create a "Intent". If you want to send information like a name, or a number or something else you can "putExtra" information like the example.
(Ofc ActivityB must to extend Activity and must be declare in AndroirManifest)
EDIT:
You have a lot of example of how to start new activity in the SDK examples (sdk directory/samples/android X )
Related
I am making an app in which, dialog pops up and user selects an option. based on this option, next activity opens up in which there is some text. There are lots of options for the user to choose from in the dialog. Every option is intended to have the same layout just the text is different. Do I need to make these many new activities or can I somehow change the string based on user's choice by adding some conditionals somewhere? Please help
You need not create separate activity for each user input, as the layout is same. You can achieve this by using a TextView and changing its text according to user input like this:
TextView textView = (TextView) findViewById(R.id.<YourTextViewID>);
textView.setText("SetTextAccordingToUserInput");
One Activity is sufficient. Set the text on selection event in dialogue.
You can use only one Activity with content and create this activity with parameter depend on user selection in dialog.
To open activity with parameter:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putInt("yourParameter", 1);
intent.putExtras(b);
startActivity(intent);
Then to use it in your SecondActivity.class onCreate method
onCreate(Bundle instance)
{
// some stuff like setting layout ant etc.
Bundle b = getIntent().getExtras();
int value = b.getInt("yourParameter");
}
I downloaded from Android.com an example of Navigation Drawer (I want to make a Slideout)
but, in that example when I click in a item of the slideout, this will open an image, so, How can i open an Activity instead of an image?
please help me.
Use this code on press ( Button press or whatever is relavant to you)
Intent intent = new Intent(Currentactivity.this,Activitytoopen.class);
startActivity(intent);
Here:
1) Currentactivity.this should be replaced with the class name you are currently on.
2) Activitytoopen.class should be replaced with the activity name you want to navigate to.
Try to use this codes
Intent i = new Intent(Activity.this,NextActivity.class);
startActivity(i);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
What's the steps of creating & Open new Screen in Android.
I am using Eclipse IDE
What i mean by new screen is when i click on button it will take me to next screen(layout)
I assume you mean Activities by "new screens". Well:
With the new ADT v. 20 it is very easy. Right-click on your project and then click on new -> other:
Click on Android Activity:
Now Name your Class
Start the Activity from your first Activity (from a Button etc.) like this:
Intent i = new Intent(firstActivity.this, secondActivity.class);
startActivity(i);
Isn't it obvious to look up for Google guideline before asking here?
http://developer.android.com/training/basics/firstapp/index.html
I'm pretty new to Android applications. What I have at the moment is an "app", which displays a login screen, and users can log in. What I want is, if the login is correct, to "forward" or open a new window, where users can change some settings etc... So really, I only need help with creating a new window.
How would one do that? Make a new activity perhaps?
Thanks
That's right, you just start a new activity with startActivity()
Intent intent = new Intent();
intent.setClass(this,SecondActivity.class);
startActivity(intent);
This means the class you come from, so the current one. SecondActivity is the activity you want to start.
I was wondering, how would I make a switch statement, that when that certain case was triggered, it would open a new screen with text. Would I use an intent? And if so, which one?
Thank you for your help in advance.
When you want to open a "new screen", you probably want to open a new activity. You would create a second Activity-derived class and use the following overload of the Intent constructor with startActivity:
Intent intent = new Intent(this, MySecondActivity.class);
startActivity(intent);
this will explicitly attempt to open a new Activity with the class name MySecondActivity
to pass a String of text from one Activity to another in this way, you can add it to the intent.
String someValue = "Some Value";
intent.putExtra("Some Key", someValue);
and in the code of your other Activity, you can get at this string via the Intent
getIntent().getStringExtra("Some Key");
Obviously you want to do null checks to make sure the key exists in the Intent, and you want to put a proper constant String somewhere instead of using a literal String for a key, but this is the basic gist.
Kriem... As Rich said you can launch a new activity using intents and push data to the new activity using extras. You can push data back to your main activity using startActivityForResult instead of startActivity. You can return to your main screen by calling finish() in the new screen. Finally, you can put the new screen event handlers into the NewScreen.java file.
The overall effect is a near full separation from dependency between the two activities, so that you might be able to easily re-use the NewScreen.java class in another project. I have some code here.