Android Gallery - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Gallery class.

This code example shows how to use the following methods:getOnItemSelectedListener, setOnItemSelectedListener
	private OnItemSelectedListener galleryListener;
	private boolean galleryListen = false;
	 
	public void listen(Gallery gallery){
		 
		galleryListener = gallery.getOnItemSelectedListener();
		galleryListen = true;
		 
		gallery.setOnItemSelectedListener(this);
	} 
 
	@Override 
	public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
		 
		invoke(parent, v, pos, id);
	 
		if(galleryListener != null){
			galleryListener.onItemSelected(parent, v, pos, id);
		} 
		 
7
CodeRank
This code example shows how to use the following methods:setAdapter, setSpacing, setOnItemClickListener, setOnItemSelectedListener
        super(c);
        tabs = new LinkedList < TabParams > ();
        tabsForViews = new HashMap < View, TabParams > ();
 
        title = new TextView(c);
        gallery = new Gallery(c);
        galleryAdapter = new TabsAdapter();
        gallery.setAdapter(galleryAdapter);
        gallery.setSpacing(0);
 
        gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> gallery, View view, int index, long id) {
                title.setText(tabs.get(index).title);
            } 
 
            public void onNothingSelected(AdapterView<?> gallery) {
                title.setText("");
            } 
        }); 
 

6
CodeRank
This code example shows how to use the following methods:getSelectedItemPosition
    public void onNothingSelected(AdapterView parent) {
    } 
     
    @Override 
    public boolean onTouchEvent(MotionEvent event) {
        selectWallpaper(mGallery.getSelectedItemPosition());
        return true; 
    } 
 
    public class ImageAdapter extends BaseAdapter {
 
        private Context mContext;
         
        public ImageAdapter(Context c) {
            mContext = c;
        } 
 
        public int getCount() { 
            return THUMB_IDS.length;
        } 
6
CodeRank
This code example shows how to use the following methods:
	private ArrayAdapter<String> arrayAdapter;
 
    @Before 
    public void setUp() throws Exception { 
        context = new Activity();
        adapterView = new Gallery(context);
		spinner = new Spinner(context);
		shadowSpinner = (ShadowAbsSpinner) Robolectric.shadowOf(spinner);
		String [] testItems = {"foo", "bar"};
		arrayAdapter = new MyArrayAdapter(this.context, testItems);
    } 
 
    @Test 
    public void shouldHaveAdapterViewCommonBehavior() throws Exception { 
        AdapterViewBehavior.shouldActAsAdapterView(adapterView);
    } 
 
	@Test 
	public void checkSetAdapter() { 
		spinner.setAdapter(arrayAdapter);
6
CodeRank
This code example shows how to use the following methods:ofFloat, getLayoutParams, setSpacing, setAdapter
This code example shows how to use the following methods:getCount, setSelection, getSelectedItemPosition
        mButtonNext.setOnClickListener(new Button.OnClickListener()
        { 
			@Override 
			public void onClick(View v) {
				// TODO Auto-generated method stub 
				int ppos = mGallery.getSelectedItemPosition();
				if (ppos < mGallery.getCount()-1){
					mGallery.setSelection(ppos+1);
				} 
			} 
        }); 
         
        mButtonWall.setOnClickListener(new Button.OnClickListener()
        { 
 
			@Override 
			public void onClick(View vc) {
				// TODO Auto-generated method stub 
				int ppos = mGallery.getSelectedItemPosition();
				try{					 
6
CodeRank
This code example shows how to use the following methods:getSelectedItemPosition
            return image;
        } 
    } 
 
    public void onClick(View v) {
        selectWallpaper(mGallery.getSelectedItemPosition());
    } 
 
    class WallpaperLoader extends AsyncTask<Integer, Void, Bitmap> {
        BitmapFactory.Options mOptions;
 
        WallpaperLoader() { 
            mOptions = new BitmapFactory.Options();
            mOptions.inDither = false;
            mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
        } 
 
        @Override 
		protected Bitmap doInBackground(Integer... params) {
            if (isCancelled()) return null;
5
CodeRank
This code example shows how to use the following methods:setVisibility, getSelectedItemPosition
			return image;
		} 
	} 
 
	public void onClick(View v) {
		gallery.setVisibility(View.INVISIBLE);
		selectWallpaper(gallery.getSelectedItemPosition());
	} 
 
	private class WallpaperLoader extends AsyncTask<Integer, Void, Bitmap> {
		BitmapFactory.Options options;
 
		WallpaperLoader() { 
			options = new BitmapFactory.Options();
			options.inDither = false;
			options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		} 
 
		protected Bitmap doInBackground(Integer... params) {
			if (isCancelled())
5
CodeRank
This code example shows how to use the following methods:setId, setAdapter, setOnItemClickListener
        	int padding = Math.round(10*scale);
        	title_view.setPadding(0, 0, 0, padding);
    		this.addView(title_view,params);
    		title_view.setText("Click on thumbnail to view image");
    		 
    		gallery = new Gallery(context);
    		gallery.setId(GALLERY_ID);
    		params = new RelativeLayout.LayoutParams(
    				ViewGroup.LayoutParams.FILL_PARENT,
    				ViewGroup.LayoutParams.WRAP_CONTENT);
    		params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    		params.addRule(RelativeLayout.BELOW,TITLE_ID);
    		this.addView(gallery,params);
    		 
    		gallery.setAdapter(adapter);
    		 
    		gallery.setOnItemClickListener(new OnItemClickListener() {
    	        public void onItemClick(AdapterView parent, View v, int position, long id) {
    	            // TODO show new activity with image 
    	        	Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();

5
CodeRank
This code example shows how to use the following methods:getSelectedItemPosition
    public void onClick(DialogInterface dialog, int which) {
        if (mCallback != null) {
			 
			hsel = hour.getSelectedItemPosition();
			msel = min.getSelectedItemPosition();
			ssel = sec.getSelectedItemPosition();
			 
            int[] values = {hsel,msel,ssel};
            mCallback.onNumbersPicked(values);
        } 
    } 
} 
5
CodeRank

Related Android Gallery Questions & Answers:

See Code Examples for Android Gallery Methods: