Reputation: 88
I have created the grid view and inserted some images in that grid now when i click on the any image it should open as a full screen and now when i slide to right or left the image have to be switched(another image has to open) here is the code so far i have done
public class ChaildHood extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.g_view);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(ChaildHood.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
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(10, 10, 10,10);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.child,
R.drawable.child1,
};
}
}
this is the g_view xml:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
Upvotes: 0
Views: 776
Reputation: 34765
In onclick event however you get position of item clicked so just design a new layout file with imageview will width and height fill parent and create a activity that show this layout file.
Now on onclick just call this start this activity and pass the position as argument(using bundle). In the activity you get the argument and show the desired image. Then you can just implent swipe left and swipe right events in on touch method. just increase and decrease the position value and show the new image from your array of images on the same activity.
Upvotes: 1
Reputation: 1704
You could get the ImageResource of the view and use the result to create a new fullscreen View using the drawable.
It's something you could have figured out yourself.
Upvotes: 1