public class Imageswitcheractivity extends Activity implements Onclicklistener,
viewfactory {
All to display the picture resource index
private static final integer[] ImageList = {R.drawable.button1,
R.drawable.button2, R.drawable.button3, R.drawable.button31,
R.drawable.ic_launcher};
Create a Imageswitcher object
Private Imageswitcher M_switcher;
Index
private static int index = 0;
"Next" button ID
private static final int button_dwon_id = 0x123456;
"Previous" button ID
private static final int button_up_id = 0x123457;
ID of the Imageswitcher object
private static final int switcher_id = 0x123458;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Create a linear layout linearlayout
LinearLayout Main_view = new LinearLayout (this);
Chuang Imageswithcer Object
M_switcher = new Imageswitcher (this);
Add a imageswitcher view to a linear layout
Main_view.addview (M_switcher);
Set the ID of the Imageswither object
M_switcher.setid (switcher_id);
Set the data source for the Imageswithcer object
M_switcher.setfactory (this);
M_switcher.setimageresource (Imagelist[index]);
Set the display of the linear layout created above
Setcontentview (Main_view);
Set Button Position Properties
Linearlayout.layoutparams param = new Linearlayout.layoutparams (
100, 100);
Create "Next" button
button next = New button (this);
Next.setid (button_dwon_id);
Next.settext ("next One");
Next.setonclicklistener (this);
Main_view.addview (Next, Param);
Create a "previous" button
button pre = New button (this);
Pre.setid (button_up_id);
Pre.settext ("previous one");
Pre.setonclicklistener (this);
Main_view.addview (pre, param);
}
@Override
Public View Makeview () {
Show all pictures through ImageView
return new ImageView (this);
}
Event monitoring, processing
@Override
public void OnClick (View v) {
Switch (V.getid ()) {
Next page
Case BUTTON_DWON_ID:
index++;
if (index >= imagelist.length) {
index = 0;
}
Set Imageswithcer Object Resource Index
M_switcher.setimageresource (Imagelist[index]);
Break
Case BUTTON_UP_ID:
index--;
if (Index < 0) {
index = imagelist.length-1;
}
Set Imageswithcer Object Resource Index
M_switcher.setimageresource (Imagelist[index]);
Break
Default
Break
}
}
}
Android--imageswitcher Picture Toggle