Java Code Examples for android.widget.GridView#setChoiceMode()

The following examples show how to use android.widget.GridView#setChoiceMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreferencesFragment.java    From Android-PreferencesManager with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    loadingView = view.findViewById(R.id.loadingView);
    emptyView = view.findViewById(R.id.emptyView);
    emptyViewText = (TextView) view.findViewById(R.id.emptyViewText);
    gridView = (GridView) view.findViewById(R.id.gridView);
    gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);

    updateFilter(null);

    if (preferenceFile == null) {
        launchTask();
    } else {
        updateListView(preferenceFile, false);
    }
}
 
Example 2
Source File: LocalPhotosGridFragment.java    From glimmr with Apache License 2.0 5 votes vote down vote up
@Override
protected void initGridView() {
    mGridView = (GridView) mLayout.findViewById(R.id.gridview);
    mGridView.setVisibility(View.VISIBLE);
    mGridView.setMultiChoiceModeListener(this);
    mShowDetailsOverlay = false;
    String[] from = {MediaStore.MediaColumns.TITLE};
    int[] to = {android.R.id.text1};

    CursorLoader cursorLoader = new CursorLoader(
            getActivity(),
            SOURCE_URI,
            null,
            null,
            null,
            MediaStore.Audio.Media.TITLE);

    Cursor cursor = cursorLoader.loadInBackground();

    mAdapter = new MediaStoreImagesAdapter(
            getActivity(),
            R.layout.gridview_item,
            cursor,
            from,
            to);

    mGridView.setAdapter(mAdapter);
    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        final String usageTip = getString(R.string.upload_photos_tip);
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            UsageTips.getInstance().show(mActivity, usageTip, true);
        }
    });
}
 
Example 3
Source File: Grid3.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    loadApps();

    setContentView(R.layout.grid_1);
    mGrid = (GridView) findViewById(R.id.myGrid);
    mGrid.setAdapter(new AppsAdapter());
    mGrid.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGrid.setMultiChoiceModeListener(new MultiChoiceModeListener());
}
 
Example 4
Source File: ExtendedCalendarView.java    From ExtendedCalendarView with Apache License 2.0 4 votes vote down vote up
private void init(){
	cal = Calendar.getInstance();
	base = new RelativeLayout(context);
	base.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
	base.setMinimumHeight(50);
	
	base.setId(4);
	
	LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.leftMargin = 16;
	params.topMargin = 50;
	params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	prev = new ImageView(context);
	prev.setId(1);
	prev.setLayoutParams(params);
	prev.setImageResource(R.drawable.navigation_previous_item);
	prev.setOnClickListener(this);
	base.addView(prev);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.addRule(RelativeLayout.CENTER_HORIZONTAL);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	month = new TextView(context);
	month.setId(2);
	month.setLayoutParams(params);
	month.setTextAppearance(context, android.R.attr.textAppearanceLarge);
	month.setText(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())+" "+cal.get(Calendar.YEAR));
	month.setTextSize(25);
	
	base.addView(month);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.rightMargin = 16;
	params.topMargin = 50;
	params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	next = new ImageView(context);
	next.setImageResource(R.drawable.navigation_next_item);
	next.setLayoutParams(params);
	next.setId(3);
	next.setOnClickListener(this);
	
	base.addView(next);
	
	addView(base);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.bottomMargin = 20;
	params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	params.addRule(RelativeLayout.BELOW, base.getId());
	
	calendar = new GridView(context);
	calendar.setLayoutParams(params);
	calendar.setVerticalSpacing(4);
	calendar.setHorizontalSpacing(4);
	calendar.setNumColumns(7);
	calendar.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
	calendar.setDrawSelectorOnTop(true);
	
	mAdapter = new CalendarAdapter(context,cal);
	calendar.setAdapter(mAdapter);
	calendar.setOnTouchListener(new OnTouchListener() {
		
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return calendarGesture.onTouchEvent(event);
        }
    });
	
	addView(calendar);
}
 
Example 5
Source File: ManageDownloadsActivity.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onStart() {
	super.onStart();
	
	gridView = (GridView) findViewById(R.id.grid);
	gridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
	gridView.setMultiChoiceModeListener(multiChoiceModeListener);
	gridView.setOnItemClickListener(itemClickListener);
	
	View emptyView = getLayoutInflater().inflate(R.layout.listview_empty, null, false);
	((TextView) emptyView.findViewById(R.id.text_list_empty)).setText(R.string.msg_no_downloaded_videos);
	ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	addContentView(emptyView, p);
	
	gridView.setEmptyView(emptyView);
	
	requestDataService(new ObjectCallback<KADataService>() {
		@Override
		public void call(final KADataService dataService) {
			ManageDownloadsActivity.this.dataService = dataService;
			
			CursorAdapter adapter = new Adapter(ManageDownloadsActivity.this, null, 0, dataService.getThumbnailManager());
			gridView.setAdapter(adapter);

			new AsyncTask<Void, Void, Cursor>() {
				@Override
				protected Cursor doInBackground(Void... arg) {
					return getCursor();
				}
				
				@Override
				protected void onPostExecute(Cursor cursor) {
					((CursorAdapter) gridView.getAdapter()).changeCursor(cursor);
				}
			}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			
			final ActionBar ab = getActionBar();
			ab.setDisplayHomeAsUpEnabled(true);
			
			ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
			ab.setTitle("");
			
			setupListNavigation();
			
			// The receiver performs actions that require a dataService, so register it here.
			IntentFilter filter = new IntentFilter();
			filter.addAction(ACTION_LIBRARY_UPDATE);
			filter.addAction(ACTION_BADGE_EARNED);
			filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED);
			filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE);
			filter.addAction(ACTION_TOAST);
			broadcastManager.registerReceiver(receiver, filter);
		}
	});
}