Image selector Multi-image-selector (homemade)

Source: Internet
Author: User
Quick Start

The No. 0 step is to add the module Multi-image-selector as your project dependencies to the project.

The 1th step is to add permission Android.permission.READ_EXTERNAL_STORAGE to your Androidmanifest.xml file. Don't forget to declare multiimageselectoractivity this activity in Androidmanifest.xml.

<activity
    android:configchanges= "orientation|screensize"
    android:name= "Me.nereo.multi_image_ Selector. Multiimageselectoractivity "/>
The 2nd step of the code is called, for example:
Intent Intent = new Intent (Mcontext, multiimageselectoractivity.class);

Whether to show call camera
to take picture Intent.putextra (Multiimageselectoractivity.extra_show_camera, true);

Maximum picture selection number
Intent.putextra (Multiimageselectoractivity.extra_select_count, 9);

Setup mode (supports radio/multiimageselectoractivity.mode_single or multiple selection/multiimageselectoractivity.mode_multi)
Intent.putextra (Multiimageselectoractivity.extra_select_mode, multiimageselectoractivity.mode_multi);

Startactivityforresult (Intent, request_image);
The 3rd step is to accept the result in your Onactivityresult method. For example:
@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data) {
    Super.onactivityresult (Requestcode, ResultCode, data);
    if (Requestcode = = request_image) {
        if (ResultCode = = RESULT_OK) {
            //Get the Returned picture List
            list<string> path = Data.getstringarraylistextra (Multiimageselectoractivity.extra_result);
            Deal with your own logic ....}}
The 4th step is not 4th step, so it is OK ~:) Custom Displaycustomizing activity
Class Customeractivity extends Activity implements multiimageselectorfragment.callback{@Override protected void O
        Ncreate (Bundle savedinstancestate) {//Your own logic ...
        Bundle bundle = new bundle ();
        Bundle.putint (Multiimageselectorfragment.extra_select_count, Mdefaultcount);
        Bundle.putint (Multiimageselectorfragment.extra_select_mode, MODE);
        <bundle class= "Putbo" ></bundle>olean (Multiimageselectorfragment.extra_show_camera, isShow); Add main fragment to Activity Getsupportfragmentmanager (). BeginTransaction (). Add (R.id.image_grid, FRAGM
    Ent.instantiate (this, MultiImageSelectorFragment.class.getName (), bundle)). commit (); } @Override public void onsingleimageselected (String path) {//When the selection mode is set to Radio/mode_single, this method will accept fragment
    The returned data} @Override public void onimageselected (String path) {//A picture is selected to be triggered, and here you can customize your own actionbar behavior } @Override Public VOID onimageunselected (String path) {//A picture being reversed is triggered, and here you can customize your own Actionbar behavior} @Override public void OnC Amerashot (file ImageFile) {//When the camera is set, the user will return a photo file after taking a picture}}
Specifically, you can refer to the implementation of Multiimageselectoractivity.java

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.