I have an array of images in an imageView. : final int[] imageArray =
{R.drawable.image1, R.drawable.image2, R.drawable.image3,
R.drawable.image4, R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9};
I want it so that if the current drawable in the ImageView is R.drawable.image6, when clicked, the link is google. If the current drawable in the ImageView is R.drawable.image7, when clicked, is linked to amazon.com. **two random sites, just for testing purposes
I have tried writing something like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
final ImageView imageview = (ImageView) findViewById(R.id.imageView1);
imageview.setOnClickListener(new View.OnClickListener() {
if(imageArray[position]==R.drawable.image6)
{
public void onClick (View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://google.com"));
startActivity(intent);
}
}
else if(imageArray[position]==R.drawable.image7)
{
public void onClick (View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://amazon.com"));
startActivity(intent);
}
}
}
but this ends up with multiple errors. Can someone help me out here and point me in the right direction?
Aucun commentaire:
Enregistrer un commentaire