In my app, I want the background image to change when tapping on the image (this works perfectly), but now I was thinking of maybe having it to change automatically without tapping the image.
Here is my code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
((ViewSwitcher) rootView.findViewById(R.id.switcher)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewSwitcher switcher = (ViewSwitcher) v;
if (switcher.getDisplayedChild() == 0) {
switcher.showNext();
} else {
switcher.showPrevious();
}
}
});
return rootView;
}
}
How can I make it to change automatically?
I have tried various suggestions, but nothing seems to work or it just displays the first image.