Android--imageswitcher Picture Toggle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.