views:

14

answers:

1

I am developing an app that is gonna be like a "comicApp", but so far I've just created 2 buttons and then I got 2 .jpgs.

So when I click the first button I want to show a .jpg file in a new screen. I got 2 layout XML's (Main and the one with the ImageView on it.)

How do I create a new screen in the activity?

This is what I got so far -

package com.comics;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class Comics extends Activity {



    ImageView iv;
    Button btn;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // setContentView  
            setContentView(R.layout.main); /main.xml
            iv = (ImageView)this.findViewById(R.id.ImageView01); android:id="@+id/image"
            btn = (Button)this.findViewById(R.id.ButtonKalleAnka);   android:id="@+id/button"

            btn.setOnClickListener(new OnClickListener(){ 

                    @Override
                    public void onClick(View v) { 
                        iv.setImageResource (R.drawable.ka1);  filnamnet. Du skall inte skriva .jpg ex R.drawable.bild.jpg 
                    }

            });
        }
}
A: 

You want to create a new activity for the new view, and then create an intent to start that activity:

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

If you haven't yet, I'd recommend reading through Application Fundamentals.

Mayra