Ronnie
Ronnie

Reputation: 11198

Basic layout/navigation question for android development

What is the best approach for navigating between "windows" in an android app?

I say "windows" because I dont the proper terminology in java. I just started.

Lets say the first screen the user sees is a username and password input with a button. On successful login, it shows a whole new "window" with relevant logged in information?

I attempted putting 2 EditTexts and a Button inside a view (using the Main.xml graphical layout tab[eclipse]) in main.xml, but it did not like that.

Upvotes: 3

Views: 4329

Answers (6)

Thanks
Thanks

Reputation: 5

Intent intent = new Intent(this, otherclassname.class);

  intent.putExtra("userid", userfield);  //sends the userid

  startActivity(intent);

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.showhistoricweek);


    senduserid = getIntent().getIntExtra("userid", 0); //gets the userid

Upvotes: 0

YoYoMyo
YoYoMyo

Reputation: 904

This is a excerpt from the page http://developer.android.com/guide/topics/fundamentals.html

Activities An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.

Here's an tutorial on how to switch between activities: http://www.warriorpoint.com/blog/2009/05/24/android-how-to-switch-between-activities/

Don't for get to add every activity to AndroidManifest.xml!

Upvotes: 3

John Leehey
John Leehey

Reputation: 22240

There's a lot to understand, I'd recommend going through some tutorials before diving right in. For each "window" (called content views in android), there should be an underlying Activity.

The Labs taught here from a college course at Cal Poly SLO helped me get very familiar with Android quickly.

Upvotes: 0

Gligor
Gligor

Reputation: 2940

You can consider activities as being "windows" for android.

Create different layout XMLs for your different activities and on a button click from activity A start activity B and close A... to give an example:

// in activity A for the button click:

public void onButtonClick(View view) {
    Intent intent = new Intent(this, B.class);
    activity.startActivity(intent);
    activity.finish();
}






// in activity B you have:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.B); //using your B.xml layout
}

Upvotes: 1

Bill Mote
Bill Mote

Reputation: 12823

The "windows" in Android are called Activities and you move between them with Intents.

Intent intent = new Intent(GroupPickerActivity.this, SmsActivity.class);
startActivity(intent);

Upvotes: 0

pheelicks
pheelicks

Reputation: 7469

The Android way of doing it is to use an Activity for each 'window', as you call them. You move between Activities by using startActivity().

You shouldn't have any problem putting 2 edittexts & a button inside an xml layout, so the problem you're having is probably related to something else. Have you checked the log output for errors? Something that gets a lot of newcomers is that you have to declare every Activity in your mainfest file, otherwise Android will not load it.

Upvotes: 0

Related Questions