Example usage for android.widget Gallery setAdapter

List of usage examples for android.widget Gallery setAdapter

Introduction

In this page you can find the example usage for android.widget Gallery setAdapter.

Prototype

@Override
public void setAdapter(SpinnerAdapter adapter) 

Source Link

Document

The Adapter is used to provide the data which backs this Spinner.

Usage

From source file:com.tarsoft.openlibra.ollista.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // prevent the default title-bar from being displayed
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ollista);/*w  w w .  j ava2s  .  c om*/

    //Create BBDD object
    DAO = new DBOpenLibra(this);

    //ActionBar        
    mActionBar = (ActionBar) findViewById(R.id.actionBar);
    mActionBar.setTitle(R.string.app_name);

    // set home icon that does nothing when the user clicks on it
    mActionBar.setHomeLogo(R.drawable.icon);

    mActionBar.addActionIcon(R.drawable.refresh, new OnClickListener() {
        @Override
        public void onClick(View v) {
            //load data on activity adapters
            loadData(true);
        }
    });

    mActionBar.addActionIcon(R.drawable.change, new OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ollista.this, "Clicked on an Icon Change", Toast.LENGTH_SHORT).show();
        }
    });

    // sets an action icon that displays a Toast upon clicking
    mActionBar.addActionIcon(R.drawable.search, new OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ollista.this, "Clicked on an Icon Search", Toast.LENGTH_SHORT).show();
        }
    });

    //Data
    listerMost = (ListView) findViewById(R.id.list2);

    if (adapterLast == null) {
        adapterLast = new listaOLIconArrayAdapter(ollista.this, listaLast);
    }

    //Covers gallery        
    Gallery gallery = (Gallery) findViewById(R.id.gallery);
    gallery.setAdapter(adapterLast);

    /*
    gallery.setOnItemClickListener(new OnItemClickListener() {
            
       public void onItemClick(AdapterView parent, View v, int position, long id) {
                
      Toast.makeText(ollista.this, "" + position, Toast.LENGTH_SHORT).show();
    }
            
    });
    */

    //Most viewed list
    if (adapterMost == null) {
        adapterMost = new listaOLArrayAdapter(ollista.this, listaMost);
    }

    listerMost.setTextFilterEnabled(true);
    listerMost.setItemsCanFocus(true);
    listerMost.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    listerMost.setAdapter(adapterMost);

    //Evaluate Internet available
    try {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo checkInternet = cm.getActiveNetworkInfo();
        if (checkInternet != null && checkInternet.isConnectedOrConnecting()) {
            checkConexion = true;
        } else {
            checkConexion = false;
        }

    } catch (Exception e) {
        e.printStackTrace();
        Log.d(TAG, "Error when check if internet available: " + e.toString());
    }

    //load data on activity adapters
    loadData(false);
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

private void updateGallery() {
    Gallery g = (Gallery) findViewById(R.id.upload_images);

    ImageUriAdapter ua = new ImageUriAdapter();
    g.setAdapter(ua);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * ADW: Put the launcher in desktop edit mode We could be able to add,
 * remove and reorder screens/*ww w.  ja  v  a 2 s .  c  om*/
 */
private void startDesktopEdit() {
    if (!mIsEditMode) {
        mIsEditMode = true;
        final PersonaWorkspace personaWorkspace = mWorkspace;
        if (personaWorkspace == null)
            return;
        personaWorkspace.enableChildrenCache(0, personaWorkspace.getChildCount());
        hideDesktop(true);
        personaWorkspace.lock();
        // Load a gallery view
        final PersonaScreensAdapter screens = new PersonaScreensAdapter(this,
                personaWorkspace.getChildAt(0).getWidth(), personaWorkspace.getChildAt(0).getHeight());
        for (int i = 0; i < personaWorkspace.getChildCount(); i++) {
            screens.addScreen((PersonaCellLayout) personaWorkspace.getChildAt(i));
        }
        mScreensEditor = mInflater.inflate(R.layout.pr_screens_editor, null);
        final Gallery gal = (Gallery) mScreensEditor.findViewById(R.id.gallery_screens);
        gal.setCallbackDuringFling(false);
        gal.setClickable(false);
        gal.setAdapter(screens);
        // Setup delete button event
        View deleteButton = mScreensEditor.findViewById(R.id.delete_screen);
        deleteButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                final int screenToDelete = gal.getSelectedItemPosition();
                if (personaWorkspace.getChildCount() > 1) {
                    AlertDialog alertDialog = new AlertDialog.Builder(PersonaLauncher.this).create();
                    alertDialog.setTitle(getResources().getString(R.string.title_dialog_xml));
                    alertDialog.setMessage(getResources().getString(R.string.message_delete_desktop_screen));
                    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    personaWorkspace.removeScreen(screenToDelete);
                                    screens.removeScreen(screenToDelete);
                                }
                            });
                    alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.cancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                }
                            });
                    alertDialog.show();
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this,
                            R.string.message_cannot_delete_desktop_screen, Toast.LENGTH_LONG);
                    t.show();
                }

            }
        });
        // Setup add buttons events
        View addLeftButton = mScreensEditor.findViewById(R.id.add_left);
        addLeftButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (screens.getCount() < MAX_SCREENS) {
                    final int screenToAddLeft = gal.getSelectedItemPosition();
                    PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddLeft);
                    screens.addScreen(newScreen, screenToAddLeft);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        View addRightButton = mScreensEditor.findViewById(R.id.add_right);
        addRightButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                if (screens.getCount() < MAX_SCREENS) {
                    final int screenToAddRight = gal.getSelectedItemPosition();
                    PersonaCellLayout newScreen = personaWorkspace.addScreen(screenToAddRight + 1);
                    screens.addScreen(newScreen, screenToAddRight + 1);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_add_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });

        final View swapLeftButton = mScreensEditor.findViewById(R.id.swap_left);
        swapLeftButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen > 0) {
                    personaWorkspace.swapScreens(currentScreen - 1, currentScreen);
                    screens.swapScreens(currentScreen - 1, currentScreen);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        final View swapRightButton = mScreensEditor.findViewById(R.id.swap_right);
        swapRightButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen < gal.getCount() - 1) {
                    personaWorkspace.swapScreens(currentScreen, currentScreen + 1);
                    screens.swapScreens(currentScreen, currentScreen + 1);
                } else {
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.message_cannot_swap_desktop_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        final View setDefaultButton = mScreensEditor.findViewById(R.id.set_default);
        setDefaultButton.setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View v) {
                int currentScreen = gal.getSelectedItemPosition();
                if (currentScreen < mWorkspace.getChildCount()) {
                    mWorkspace.setDefaultScreen(currentScreen);
                    PersonaAlmostNexusSettingsHelper.setDefaultScreen(PersonaLauncher.this, currentScreen);
                    Toast t = Toast.makeText(PersonaLauncher.this, R.string.pref_title_default_screen,
                            Toast.LENGTH_LONG);
                    t.show();
                }
            }
        });
        gal.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position <= 0) {
                    swapLeftButton.setVisibility(View.GONE);
                } else {
                    swapLeftButton.setVisibility(View.VISIBLE);
                }
                if (position < parent.getCount() - 1) {
                    swapRightButton.setVisibility(View.VISIBLE);
                } else {
                    swapRightButton.setVisibility(View.GONE);
                }
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }

        });
        mDragLayer.addView(mScreensEditor);
    }
}