Thanks all for the info. I have learned to use Bundle of extras and
GridView but I can't found the error that I am commiting. I have
modified the code:

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        /*g.setOnClickListener(new OnItemClickListener(){
                public void onItemClick(AdapterView parent, View v, int
position, long id) {

                }
        });*/
    }

    public class ImageAdapter extends BaseAdapter
    {
        private Context mContext;

        private Integer[] mThumbIds = {
                R.drawable.sample_1,
                R.drawable.sample_2,
                R.drawable.sample_3,
                R.drawable.sample_4,
                R.drawable.sample_5,
                R.drawable.sample_6,
                R.drawable.sample_7
        };

        public ImageAdapter(Context c)
        {
            mContext = c;
        }

        public int getCount()
        {
            return mThumbIds.length;
        }

        public Object getItem(int position)
        {
            return null;
        }

        public long getItemId(int position)
        {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup
parent)
        {
                ImageView imageView;

            if (convertView == null)
            {
              // if it's not recycled, initialize some attributes
              imageView = new ImageView(mContext);
              imageView.setLayoutParams(new GridView.LayoutParams(85,
85));
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setPadding(8, 8, 8, 8);

              imageView.setOnClickListener(new View.OnClickListener()
              {
                @Override
                public void onClick(View view)
                {
                    Intent intent = new Intent();
                    intent.setClass(Editor.this, Rotar.class);
                    intent.putExtra("imagen",
String.valueOf(position)); <-- I think that position has the position
of the image but I am not sure
                    startActivity(intent);
                    finish();
                }
              });
            }
            else
            {
              imageView = (ImageView) convertView;
            }

            imageView.setImageResource(mThumbIds[position]);
            return imageView;
        }
    }

In the second activity (whose name is "Rotar") I am intenting to
recupere the position that I have selected in the gallery and I am
intenting as the following mode:

Bundle extras = getIntent().getExtras();
        if(extras != null)
        {
                String value = extras.getString("imagen");
                imagen = mThumbIds[Integer.getInteger(value)];
        }

But when I click an image, the program finish with an error. The
"imagen" and "mThumbids" are declared as private variables in the
first of the class.

Thank again for your answer. A greeting.

On Mar 15, 10:02 am, Tarun Bakshi <[email protected]> wrote:
> You might use Bundle of extras to pass information from one activity to
> another activity.
>
>
>
> On Mon, Mar 15, 2010 at 2:26 PM, ReyLith <[email protected]> wrote:
> > Thank for you respond.
>
> > I am already using intent for moving from one activity to another and
> > I have declared it in the androidmanifest. The code that I am using is
> > the following:
>
> > public void onCreate(Bundle savedInstanceState)
> >    {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        Gallery g = (Gallery) findViewById(R.id.Gallery);
> >        g.setAdapter(new ImageAdapter(this));
>
> >        g.setOnItemClickListener(new OnItemClickListener()
> >        {
> >                public void onItemClick(AdapterView parent, View v, int
> > position, long id)
> >                {
> >                        //Toast.makeText(Editor.this, "" + position,
> > Toast.LENGTH_SHORT).show();
> >                }
> >        });
>
> >        ImageButton abrir = (ImageButton)
> > findViewById(R.id.ImageButton01);
> >        abrir.setOnClickListener(abrirImagen);
>
> >        ImageButton cerrar = (ImageButton)
> > findViewById(R.id.ImageButton01);
> >        cerrar.setOnClickListener(cerrarPrograma);
> >    }
>
> >   /*private OnClickListener abrirImagen = new OnClickListener()
> >    {
> >       public void onClick(View v)
> >       {
> >           Intent intent = new Intent();
> >           intent.setClass(Editor.this, Rotar.class);
> >           startActivity(intent);
> >           finish();
> >       }
> >    };*/
>
> >   private OnItemClickListener seleccionImagen = new
> > OnItemClickListener()
> >    {
> >       public void onItemClick(AdapterView parent, View v, int
> > position, long id)
> >       {
> >           Intent intent = new Intent();
> >           intent.setClass(Editor.this, Rotar.class);
> >           startActivity(intent);
> >           finish();
> >       }
> >    };
>
> > The commented function is where I use the botton and the non-commented
> > funcion is where I want to go to another activity. If someone wants I
> > can put the complete code but I think that there isn't neccesary. As
> > you can see I use intents for open the other activity but I don't know
> > how I can pass the selected image.
>
> > Greetings.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<android-developers%2Bunsubs 
> > [email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to