Wednesday, May 13, 2009

Android SDK's Guide, Image from Gallary to be Clickable

Android's Online Resource is very limited, it took me a day before I can figure out how to make those pictures in the photo gallery clickable. I am still a newbie at android development, but I have never spend this much time trying to figure out something that's this simple.

On the android's website it has Hello Gridview guide, which shows you the photo gallary. If you want further clicks from those photos following code is to be added.

All the XML has already set up in the tutorial.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.photogridview);
gridview.setAdapter(new ImageAdapter(this));

gridview.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView parent, View v, int position, long id){
GoDoWhatever();
}}});
}

protected void GoDoWhatever()
{
//Do Whatever you want to do after pictures in the gallery are being clicked
}

Hopefully this helps

No comments:

Post a Comment