Main Activity
package com.example.imagegallry;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.ListView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> urls=new ArrayList<String>();
urls.add("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTaBYSb4nVQrEn2c2xAbrQlLmbBeWuHdwScXTP4ooVzUhC9ZfKzXA");
urls.add("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRveXT-rTUftVUUbgbSTpYh1sVfFEOlah1yr1DPQ2ScY7dMR7gc");
urls.add("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRoijmXrh12Ux48kbZMPfLMlog6LatW2IplODMEX0IBqiI9JZaC");
urls.add("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSkep0_haj0l6RsmK922iADQjWj1r2MibNsbqsr6QFeLXk2TIPSSw");
urls.add("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT0k39CFKC6dKMSaMXxIKA9UoNtLL-wzBwOAhf6o3gkmEvyzqnK6w");
urls.add("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcR0XcapD77nGfmhYvucYQyzq4W2VnrLij8BCANBuZGY-1tOqGht&reload=on");
galleryadapter adp=new galleryadapter(urls, getApplicationContext());
GridView g1=(GridView)findViewById(R.id.gridView1);
g1.setAdapter(adp);
}
}
Gallery Adapter
package com.example.imagegallry;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class galleryadapter extends BaseAdapter {
List<String> myimages;
Context ctx;
public galleryadapter(List<String> images, Context applicationContext) {
myimages = images;
this.ctx = applicationContext;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return myimages.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater li = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.gridlayout, null);
ImageView img = (ImageView) convertView.findViewById(R.id.imageView1);
Picasso.with(ctx).load(myimages.get(position)).into(img);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent in=new Intent(ctx, MainActivityfull.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("img", myimages.get(position));
ctx.startActivity(in);
}
});
return convertView;
}
}
Main Activity full Image
package com.example.imagegallry;
import com.squareup.picasso.Picasso;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivityfull extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activityfull);
String img = getIntent().getStringExtra("img");
Toast.makeText(getApplicationContext(), img, 2000).show();
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
Picasso.with(getApplicationContext()).load(img).into(imageView);
}
}
Screen Shot of images in gallery
Screen Shot of full image
No comments:
Post a Comment