Example usage for android.widget AdapterView getAdapter

List of usage examples for android.widget AdapterView getAdapter

Introduction

In this page you can find the example usage for android.widget AdapterView getAdapter.

Prototype

public abstract T getAdapter();

Source Link

Document

Returns the adapter currently associated with this widget.

Usage

From source file:eu.se_bastiaan.popcorntimeremote.iab.DonationFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity activity = getActivity();/* w w  w . j  a  v  a 2s  .  com*/
    assert activity != null;

    View view = getActivity().getLayoutInflater().inflate(R.layout.donation_dialog, null, false);

    AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(R.string.donation_title)
            .setView(view).setNegativeButton(android.R.string.cancel, null);

    TextView info = (TextView) view.findViewById(R.id.info);
    info.setText(Html.fromHtml(getString(R.string.donation_info)));
    info.setMovementMethod(new LinkMovementMethod());

    mError = (TextView) view.findViewById(R.id.error);
    mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
    mGridView = (GridView) view.findViewById(R.id.grid);
    mGridView.setAdapter(new DonationAdapter(getActivity(), mDonationList, mInventorySet));
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DonationAdapter adapter = (DonationAdapter) parent.getAdapter();
            Donation donation = adapter.getItem(position);

            if (!mInventorySet.contains(donation.sku)) {
                /**
                 * See {@link sharedcode.turboeditor.iab.DonationFragment#verifyDeveloperPayload(Purchase)}.
                 */
                String payload = "";
                try {
                    mHelper.launchPurchaseFlow(getActivity(), donation.sku, RC_REQUEST,
                            mPurchaseFinishedListener, payload);
                } catch (Exception e) {
                    Toast.makeText(getActivity(), "Failed to launch a purchase flow.", Toast.LENGTH_SHORT)
                            .show();
                }
            } else {
                Toast.makeText(getActivity(), getString(R.string.donation_item_bought), Toast.LENGTH_LONG);
            }
        }
    });

    final AlertDialog alertDialog;

    alertDialog = builder.create();

    initBilling();

    return alertDialog;
}

From source file:org.secu3.android.DiagnosticsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
    ParamItemsAdapter adapter = (ParamItemsAdapter) parent.getAdapter();
    BaseParamItem i = (BaseParamItem) adapter.getItem(position);
    adapter.setValue(String.valueOf(!((ParamItemBoolean) i).getValue()), position);
    onParamItemChange(i);//from   ww w . j a  va 2 s. co m
}

From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }//w ww  .  jav  a  2  s. c  o  m
    if (view == null) {
        alphaValue = 255;
    }

    view = View.inflate(context, R.layout.brick_set_variable, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_set_variable_checkbox);

    final Brick brickInstance = this;
    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_set_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_set_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_set_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.set_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(SetVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });
    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(SetVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:org.secu3.android.ErrorsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(PreferenceManager.getDefaultSharedPreferences(this)
            .getBoolean(getString(R.string.pref_night_mode_key), false) ? R.style.AppBaseTheme
                    : R.style.AppBaseTheme_Light);

    setContentView(R.layout.activity_errors);

    receiver = new ReceiveMessages();

    errorsTextViewStatus = (TextView) findViewById(R.id.errorsStatusTextView);
    RealtimeError = (CheckBox) findViewById(R.id.errorsRealtimeErrorsCheckBox);
    ReadingInertion = (CheckBox) findViewById(R.id.errorsInertionCheckBox);

    boolean realtime = RealtimeError.isChecked();
    errors = new ArrayList<BaseParamItem>();
    errorsInertness = new int[INERTNESS_COUNT];
    String errorNames[] = getResources().getStringArray(R.array.errors_ecu_errors_names);
    String errorBCs[] = getResources().getStringArray(R.array.errors_ecu_errors_blink_codes);
    for (int i = 0; i != Secu3Packet.SECU3_ECU_ERRORS_COUNT; i++) {
        errors.add(// w w  w . j ava 2  s  .c o  m
                new ParamItemBoolean(this, errorNames[i], getString(R.string.errors_code, errorBCs[i]), false));
        errors.get(i).setEnabled(!realtime);
    }
    adapter = new ParamItemsAdapter(errors);

    RealtimeError.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView == RealtimeError) {
                setRealtime(RealtimeError.isChecked());
            }
        }
    });
    ReadingInertion.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView == ReadingInertion) {
                setInertness(ReadingInertion.isChecked());
            }
        }
    });
    RealtimeError.setChecked(false);
    ReadingInertion.setEnabled(false);

    ListView l = (ListView) findViewById(R.id.errorsListView);
    l.setAdapter(adapter);
    l.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
            adapter = (ParamItemsAdapter) parent.getAdapter();
            BaseParamItem i = (BaseParamItem) adapter.getItem(position);
            adapter.setValue(String.valueOf(!((ParamItemBoolean) i).getValue()), position);
        }

    });

    if (savedInstanceState != null) {
        setErrors(savedInstanceState.getInt(ERRORS));
        RealtimeError.setChecked(savedInstanceState.getBoolean(REALTIME));
        ReadingInertion.setChecked(savedInstanceState.getBoolean(INERTNESS));
    }
    super.onCreate(savedInstanceState);
}

From source file:com.abcvoipsip.ui.help.Help.java

@Override
public void onItemClick(AdapterView<?> av, View v, int position, long id) {
    Log.i(THIS_FILE, "Item clicked : " + id + " " + position);
    HelpArrayAdapter haa = (HelpArrayAdapter) av.getAdapter();
    HelpEntry he = haa.getItem(position);

    DialogFragment newFragment;//from  w ww . j av  a 2s  . com
    switch (he.choiceTag) {
    case FAQ:
        newFragment = Faq.newInstance();
        newFragment.show(getSupportFragmentManager(), "faq");
        break;
    case LEGALS:
        newFragment = Legal.newInstance();
        newFragment.show(getSupportFragmentManager(), "issues");
        break;
    case OPEN_ISSUES:
        Intent it = new Intent(Intent.ACTION_VIEW);
        it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        it.setData(Uri.parse("http://code.google.com/p/csipsimple/issues"));
        startActivity(it);
        break;
    case NIGHTLY:
        // We have to check for an update

        // ABC-VoIP Modification: disabled all nightly updates
        /*
        final NightlyUpdater nu = new NightlyUpdater(getActivity());
        Thread t = new Thread() {
           public void run() {
              UpdaterPopupLauncher ru = nu.getUpdaterPopup(true);
              if (ru != null) {
          getActivity().runOnUiThread(ru);
              }
           };
        };
        t.start();
        */
        break;
    case SEND_LOGS:
        prefsWrapper.setPreferenceStringValue(SipConfigManager.LOG_LEVEL, "1");
        try {
            startActivityForResult(
                    CollectLogs.getLogReportIntent("<<<PLEASE ADD THE BUG DESCRIPTION HERE>>>", getActivity()),
                    REQUEST_SEND_LOGS);
        } catch (Exception e) {
            Log.e(THIS_FILE, "Impossible to send logs...", e);
        }
        Log.setLogLevel(1);
        break;
    case START_LOGS:
        prefsWrapper.setPreferenceStringValue(SipConfigManager.LOG_LEVEL, "4");
        Log.setLogLevel(4);
        Intent intent = new Intent(SipManager.ACTION_SIP_REQUEST_RESTART);
        getActivity().sendBroadcast(intent);
        dismiss();
        break;
    default:
        break;
    }
}

From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }//from  w w w.j a  v  a 2  s  .  co  m

    view = View.inflate(context, R.layout.brick_change_variable_by, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_change_variable_checkbox);
    final Brick brickInstance = this;

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_change_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_change_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(ChangeVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });

    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(ChangeVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:com.libtop.weituR.activity.main.DocUpload.FileListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout mLinearLayout = (LinearLayout) inflater.inflate(R.layout.activity_doc_file_list, container,
            false);// w  ww. ja v a 2  s .c o  m
    listView = (ListView) mLinearLayout.findViewById(R.id.lv_doc);
    tvTitle = (TextView) mLinearLayout.findViewById(R.id.title);
    tvUpFolder = (TextView) mLinearLayout.findViewById(R.id.tv_up_folder);
    String[] splits = mPath.split("/");
    if (splits.length != 0) {
        String last = splits[splits.length - 1];
        tvUpFolder.setText(" > " + last);
    }
    tvUpFolder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            upFolder();
        }
    });
    tvEmpty = (TextView) mLinearLayout.findViewById(R.id.tv_empty);
    tvCommit = (TextView) mLinearLayout.findViewById(R.id.commit);
    tvTitle.setText("");
    tvCommit.setText("??");
    tvCommit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchDoc();
        }
    });
    imgBack = (ImageView) mLinearLayout.findViewById(R.id.back_btn);
    listView.setAdapter(mAdapter);
    imgBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            FileListAdapter adapter = (FileListAdapter) parent.getAdapter();
            if (adapter != null) {
                File file = (File) adapter.getItem(position);
                mPath = file.getAbsolutePath();
                mListener.onFileSelected(file);
            }
        }
    });

    return mLinearLayout;
}

From source file:com.media.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        // move position to first element
        mCursor.moveToFirst();/*w w  w.j ava 2 s .  co  m*/

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:com.dazone.crewchat.libGallery.fragment.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        //move position to first element
        mCursor.moveToFirst();// w  ww.  jav a 2  s . co m

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}

From source file:csms19.inapp.msg.customgallery.VideoFragment.java

private void setAdapter() {
    int count = mCursor.getCount();

    if (count > 0) {
        mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA);

        // move position to first element
        mCursor.moveToFirst();//from  w ww  .j a  v  a 2  s . co m

        mGalleryModelList = new ArrayList<MediaModel>();
        for (int i = 0; i < count; i++) {
            mCursor.moveToPosition(i);
            String url = mCursor.getString(mDataColumnIndex);
            mGalleryModelList.add(new MediaModel(url, false));
        }

        mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true);
        mVideoAdapter.videoFragment = this;
        mVideoGridView.setAdapter(mVideoAdapter);
        mVideoGridView.setOnScrollListener(this);
    } else {
        Toast.makeText(getActivity(), "no media file available", Toast.LENGTH_SHORT).show();

    }

    mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "video/*");
            startActivity(intent);
            return false;
        }
    });

    mVideoGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        true);

                // comment start 14Jan

                /*if (size != 0) {
                   Toast.makeText(
                getActivity(),
                "The file size exceeds the maximum limit of"
                      + "  "
                      + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB
                      + " " + "MB", Toast.LENGTH_SHORT)
                .show();
                   return;
                }*/

                // comment end

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                "Max limit" + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file",
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                "Max limit" + "  " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;
            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onVideoSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });

}