I have an arraylist with some Integer[] inside and I want to display
elements of my Integer[] into a ViewFlipper.
I have the function which works if you include directly an Integer[] :
View addImageView(int resId) {
ImageView iv = new ImageView(this);
iv.setImageResource(resId);
return iv;
}
To allow the arraylist<>.get(i) to refer to my integer[] I have to modify
the type of data passed in my function:
View addImageView(Integer[] integers) {
ImageView iv = new ImageView(this);
iv.setImageResource(integers);
return iv;
}
But it returns :
The method setImageResource(int) in the type ImageView is not
applicable for the arguments (Integer[])
Is there an equivalent to make the function work ?
(if you want to see the full class, I've joined it)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package com.ctai.irisst;
import java.util.ArrayList;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.animation.AnimationUtils;
import android.view.View.OnTouchListener;
import android.view.GestureDetector;
import android.widget.ViewFlipper;
import android.widget.ImageView;
import android.view.MotionEvent;
import android.content.Context;
import android.app.Activity;
import android.widget.Toast;
import android.os.Bundle;
import android.view.View;
public class ChoixMemo extends Activity {
@SuppressWarnings("deprecation")
private final GestureDetector detector = new GestureDetector(new
MyGestureDetector());
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private static final int SWIPE_MIN_DISTANCE = 120;
private Context mContext;
private ViewFlipper vf;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choixmemo);
mContext = this;
vf = (ViewFlipper) this.findViewById(R.id.vfShow);
vf.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final
MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(ListeImages.theme_amiante_couv.length);
al.add(ListeImages.theme_amiante_couv.length);
al.add(ListeImages.theme_agencement_couv.length);
al.add(ListeImages.theme_agencement_couv.length);
al.add(ListeImages.theme_bruits_virations_couv.length);
al.add(ListeImages.theme_addictions_couv.length);
al.add(ListeImages.theme_risque_chimique_couv.length);
al.add(ListeImages.theme_formation_couv.length);
al.add(ListeImages.theme_risque_routier_couv.length);
al.add(ListeImages.theme_travail_hauteur_couv.length);
al.add(ListeImages.metier_plombier_couv.length);
al.add(ListeImages.metier_electricien_couv.length);
al.add(ListeImages.metier_carreleur_couv.length);
al.add(ListeImages.metier_peintre_couv.length);
al.add(ListeImages.metier_pierre_couv.length);
al.add(ListeImages.metier_platre_couv.length);
al.add(ListeImages.metier_charpentier_couv.length);
al.add(ListeImages.metier_serrurier_couv.length);
ArrayList<Integer[]> al1 = new ArrayList<Integer[]>();
al1.add(ListeImages.theme_amiante_couv);
al1.add(ListeImages.theme_amiante_couv);
al1.add(ListeImages.theme_agencement_couv);
al1.add(ListeImages.theme_agencement_couv);
al1.add(ListeImages.theme_bruits_virations_couv);
al1.add(ListeImages.theme_addictions_couv);
al1.add(ListeImages.theme_risque_chimique_couv);
al1.add(ListeImages.theme_formation_couv);
al1.add(ListeImages.theme_risque_routier_couv);
al1.add(ListeImages.theme_travail_hauteur_couv);
al1.add(ListeImages.metier_plombier_couv);
al1.add(ListeImages.metier_electricien_couv);
al1.add(ListeImages.metier_carreleur_couv);
al1.add(ListeImages.metier_peintre_couv);
al1.add(ListeImages.metier_pierre_couv);
al1.add(ListeImages.metier_platre_couv);
al1.add(ListeImages.metier_charpentier_couv);
al1.add(ListeImages.metier_serrurier_couv);
for (int i = 0; i < 17; i++) {
if (getIntent().getIntExtra("data", 0) == i){
for (int u = 0; u < al.get(i); u++) {
vf.addView(addImageView(al1.get(i)));
String value = String.valueOf(i);
Toast.makeText(getApplicationContext(),
value, Toast.LENGTH_SHORT).show();
}
}
}
}
View addImageView(Integer[] integers) {
ImageView iv = new ImageView(this);
iv.setResources(integers);
return iv;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX,
float velocityY) {
try {
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) >
SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.left_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.left_out));
vf.showNext();
return true;
} else if (e2.getX() - e1.getX() >
SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) >
SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.right_out));
vf.showPrevious();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
}