Basically i got one array which has 2 image as if for now but eventually will have more.
Images from array switcher every few seconds. i'm stuck with onClick method. Ultimate goal when user clicks on that image new Activity class opens up. Each image has its own Activity class so when user clicks on it, it should be directed to that particular class.
I did got some help yesterday
public void onClick(View v) {
Intent n = null;
int id = v.getId();
switch (id){
case R.id.someId:
n = new Intent(getActivity(), FragMent1.class);
break;
case R.id.someOtherId:
n = new Intent(getActivity(), FragMent2.class);
break;
}
i can set first case statement to be "R.id.textSwitcher" but second is the problem. Because i want images animates to at one place, new R.id... means new location also new "mSwitcher1.setOnClickListener(new View.OnClickListener()"
public class Animation extends Fragment implements AnimationListener {
public HomeAnimation(){}
private static boolean flag = false;
Animation anim;
private Handler handler;
public ImageSwitcher mSwitcher,mSwitcher1;
int textToShow[] = {R.drawable.dabangg, R.drawable.car };
int messageCount = textToShow.length;
int currentIndex = -1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.imgswitch, container, false);
mSwitcher = (ImageSwitcher) v.findViewById(R.id.imageSwitcher1);
mSwitcher.setFactory(mFactory);
anim = AnimationUtils.loadAnimation(getActivity(),R.anim.fade_in);
mSwitcher.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent n = null;
int id = v.getId();
// Fragment fragment = null;
//Bundle args = new Bundle();
switch (v.getId()){
case 0:
n = new Intent(getActivity(), Fragment1.class);
getActivity().startActivity(n);
break;
case 1:
n = new Intent(getActivity(), Fragment2.class);
getActivity().startActivity(n);
break;
}
}
});
// set animation listener
anim.setAnimationListener(this);
return v;
}
public void updateTextView() {
int maxIndex = textToShow.length;
Random random = new Random();
int generatedIndex = random.nextInt(maxIndex);
mSwitcher.setImageResource(textToShow[generatedIndex]);
}
Here is a what i updated in case if anyone needs it
public void updateTextView() {
int maxIndex = textToShow.length;
Random random = new Random();
final int generatedIndex = random.nextInt(maxIndex);
mSwitcher.setImageResource(textToShow[generatedIndex]);
mSwitcher.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent n = null;
switch(generatedIndex){
case 0:
n = new Intent(getActivity(), Fragment1.class);
getActivity().startActivity(n);
break;
case 1:
n = new Intent(getActivity(), Fragment2.class);
getActivity().startActivity(n);
break;
case 2:
n = new Intent(getActivity(), Fragment3.class);
getActivity().startActivity(n);
break;
}
}
});