How to make various images in grid view clickable to different activity?
I make a grid view v=with various images targetting to various activities but i don't know about how to make these images clickable to display next activity. I know it can be done through onItemClickListener but 开发者_JAVA技巧i don't know how to do it. Plz help me out ! Any kinda help would be appreciated...!!
I'd rather use an ImageButton, but ok.
Say for each image you've got something like:
ImageView iv = new ImageView();
iv.setImageResource(R.drawable.foo);
Your Grid activity should implement View.OnClickListener, with a method something like:
public void onClick(View v){
Intent i = new Intent(this, MyNextActivity.class);
startActivity(i);
}
and then, your ImageView creation should be something like:
ImageView iv = new ImageView();
iv.setImageResource(R.drawable.foo);
iv.setOnClickListener(this); // Reference to the OnClickListener implementation
Hope it helps.
精彩评论