Display images from a Grid View in a Frame Layout

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Display images from a Grid View in a Frame Layout

Postby anngeorge » Wed Sep 16, 2009 1:21 pm

Hi,

I am new to Android Application Development. I have created a GridView of 5 images. When i click on these images from the GridView, i want them to be displayed in a frame layout. Is it possible to do this?If so can someone help me out with it?I have added the code i used to display the images in GridView below.I got this code snippet from Android site.Someone please tell me how to go forward.

Thanks.

<code>
package com.example.helloandroid;


import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;

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 0;
}

// create a new ImageView for each item referenced by the Adapter
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()
{
public void onClick(View v)
{
Toast t= Toast.makeText(HelloAndroid.this, "Cheers!!!!", Toast.LENGTH_SHORT);
t.show();
}
});


} else {
imageView = (ImageView) convertView;
}

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

// references to our images
private Integer[] mThumbIds = {
R.drawable.flower1,
R.drawable.flower2,
R.drawable.flower3,
R.drawable.flower4,
R.drawable.flower5
};
}

}
</code>
anngeorge
Developer
Developer
 
Posts: 36
Joined: Wed Sep 16, 2009 1:02 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests