Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

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

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.example.de.taomi2.mediachooser.fragment.BucketImageFragment.java

private void init() {
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
    mCursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {/*from  w  w w  .j  a  v a2 s. co m*/
        while (mCursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(mCursor.getInt(INDEX_BUCKET_ID),
                    mCursor.getString(INDEX_BUCKET_NAME), mCursor.getString(INDEX_BUCKET_URL));

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }

        if (mCursor.getCount() > 0) {
            mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, false);
            mGridView.setAdapter(mBucketAdapter);
        } else {
            Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                    Toast.LENGTH_SHORT).show();
        }

        mGridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                BucketEntry bucketEntry = (BucketEntry) adapter.getItemAtPosition(position);
                Intent selectImageIntent = new Intent(getActivity(), HomeFragmentActivity.class);
                selectImageIntent.putExtra("name", bucketEntry.bucketName);
                selectImageIntent.putExtra("image", true);
                selectImageIntent.putExtra("isFromBucket", true);
                getActivity().startActivityForResult(selectImageIntent,
                        MediaChooserConstants.BUCKET_SELECT_IMAGE_CODE);
            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:com.donal.superne.app.ui.chat.emojicon.EmojiconGridFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (mOnEmojiconClickedListener != null) {
        mOnEmojiconClickedListener.onEmojiconClicked((Emojicon) parent.getItemAtPosition(position));
    }//from  w ww. j  a  v a  2s. c  o  m
}

From source file:com.uf.togathor.adapters.UsersAdapter.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    User user = (User) arg0.getItemAtPosition(arg2);

    UsersManagement.setToUser(user);/*from w  ww  . j  a  va2s . co m*/
    UsersManagement.setToGroup(null);

    boolean isLoginUser = user.getId().equals(UsersManagement.getLoginUser().getId());

    if (!isLoginUser) {
        SyncModule.addUserContact(user.getId(), mActivity);
    }
}

From source file:com.example.de.taomi2.mediachooser.fragment.BucketVideoFragment.java

private void init() {
    final String orderBy = MediaStore.Video.Media.DATE_TAKEN;
    mCursor = getActivity().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {//from   w ww  .j  av a  2s  .  com
        while (mCursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(mCursor.getInt(INDEX_BUCKET_ID),
                    mCursor.getString(INDEX_BUCKET_NAME), mCursor.getString(INDEX_BUCKET_URL));

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }

        if (mCursor.getCount() > 0) {
            mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, true);
            mBucketAdapter.bucketVideoFragment = this;
            mGridView.setAdapter(mBucketAdapter);
        } else {
            Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                    Toast.LENGTH_SHORT).show();
        }
        mGridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                BucketEntry bucketEntry = (BucketEntry) adapter.getItemAtPosition(position);
                Intent selectImageIntent = new Intent(getActivity(), HomeFragmentActivity.class);
                selectImageIntent.putExtra("name", bucketEntry.bucketName);
                selectImageIntent.putExtra("isFromBucket", true);
                getActivity().startActivityForResult(selectImageIntent,
                        MediaChooserConstants.BUCKET_SELECT_VIDEO_CODE);

            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:com.learnncode.mediachooser.fragment.BucketImageFragmentForDirPicker.java

private void init() {
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
    mCursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {//from www.j av  a 2  s  .c  o m
        while (mCursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(mCursor.getInt(INDEX_BUCKET_ID),
                    mCursor.getString(INDEX_BUCKET_NAME), mCursor.getString(INDEX_BUCKET_URL));

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }

        if (mCursor.getCount() > 0) {
            mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, false);
            mGridView.setAdapter(mBucketAdapter);
        } else {
            Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                    Toast.LENGTH_SHORT).show();
        }

        mGridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                BucketEntry bucketEntry = (BucketEntry) adapter.getItemAtPosition(position);
                Intent selectedDirIntent = new Intent(getActivity(), HomeFragmentActivity.class);
                selectedDirIntent.putExtra("name", bucketEntry.bucketName);
                getActivity().setResult(MediaChooser.RESULT_OK, selectedDirIntent);
            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:de.vanita5.twittnuker.activity.support.MenuDialogFragment.java

@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    final Fragment parentFragment = getParentFragment();
    final MenuItem item = (MenuItem) parent.getItemAtPosition(position);
    if (item.hasSubMenu()) {

    } else if (parentFragment instanceof OnMenuItemClickListener) {
        ((OnMenuItemClickListener) parentFragment).onMenuItemClick(item);
        dismiss();/*from  w ww .  java 2 s .  c  o m*/
    }
}

From source file:com.nicolls.ablum.fragment.BucketImageFragment.java

private void init() {
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
    mCursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {// w ww. ja va  2 s . com
        while (mCursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(mCursor.getInt(INDEX_BUCKET_ID),
                    mCursor.getString(INDEX_BUCKET_NAME), mCursor.getString(INDEX_BUCKET_URL));

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }

        if (mCursor.getCount() > 0) {
            mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, false);
            mGridView.setAdapter(mBucketAdapter);
        } else {
            Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                    Toast.LENGTH_SHORT).show();
        }

        mGridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                BucketEntry bucketEntry = (BucketEntry) adapter.getItemAtPosition(position);
                Intent selectImageIntent = new Intent(getActivity(), HomeFragmentActivity.class);
                selectImageIntent.putExtra("name", bucketEntry.bucketName);
                selectImageIntent.putExtra("image", true);
                selectImageIntent.putExtra("isFromBucket", true);
                selectImageIntent.putExtra("pathList",
                        getActivity().getIntent().getStringArrayListExtra("pathList"));
                getActivity().startActivityForResult(selectImageIntent,
                        MediaChooserConstants.BUCKET_SELECT_IMAGE_CODE);
            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:com.nicolls.ablum.fragment.BucketVideoFragment.java

private void init() {
    final String orderBy = MediaStore.Video.Media.DATE_TAKEN;
    mCursor = getActivity().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {// w ww. ja v a  2 s  .  com
        while (mCursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(mCursor.getInt(INDEX_BUCKET_ID),
                    mCursor.getString(INDEX_BUCKET_NAME), mCursor.getString(INDEX_BUCKET_URL));

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }
        if (mCursor.getCount() > 0) {
            mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, true);
            mBucketAdapter.bucketVideoFragment = this;
            mGridView.setAdapter(mBucketAdapter);
        } else {
            Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                    Toast.LENGTH_SHORT).show();
        }
        mGridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                BucketEntry bucketEntry = (BucketEntry) adapter.getItemAtPosition(position);
                Intent selectImageIntent = new Intent(getActivity(), HomeFragmentActivity.class);
                selectImageIntent.putExtra("name", bucketEntry.bucketName);
                selectImageIntent.putExtra("isFromBucket", true);
                selectImageIntent.putExtra("pathList",
                        getActivity().getIntent().getStringArrayListExtra("pathList"));
                getActivity().startActivityForResult(selectImageIntent,
                        MediaChooserConstants.BUCKET_SELECT_VIDEO_CODE);

            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:bf.io.openshop.ux.fragments.SettingsFragment.java

/**
 * Prepare spinner with shops and pre-select already selected one.
 *
 * @param shops list of shops received from server.
 *///from  w  w  w  . j  a  v a2  s.c o m
private void setSpinShops(List<Shop> shops) {
    ShopSpinnerAdapter adapterLanguage = new ShopSpinnerAdapter(getActivity(), shops, false);
    spinShopSelection.setAdapter(adapterLanguage);

    int position = 0;
    for (int i = 0; i < shops.size(); i++) {
        if (shops.get(i).getId() == SettingsMy.getActualNonNullShop(getActivity()).getId()) {
            position = i;
            break;
        }
    }
    spinShopSelection.setSelection(position);
    spinShopSelection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Shop selectedShop = (Shop) parent.getItemAtPosition(position);

            if (selectedShop != null
                    && selectedShop.getId() != SettingsMy.getActualNonNullShop(getActivity()).getId()) {

                RestartDialogFragment rdf = RestartDialogFragment.newInstance(selectedShop);
                rdf.show(getFragmentManager(), RestartDialogFragment.class.getSimpleName());
            } else {
                Timber.e("Selected null or same shop.");
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Timber.d("Nothing selected");
        }
    });
}

From source file:edu.rowan.app.fragments.HomescreenFragment.java

/**
 * Handle the buttons in the GridView /*from ww w  .  j  ava  2  s.  c  o m*/
 */
@Override
public void onItemClick(AdapterView<?> adapter, View view, int pos, long id) {
    String itemClicked = (String) adapter.getItemAtPosition(pos);

    if (itemClicked.equals(getResources().getString(R.string.currentStudents))) {
        activity.perform(ApplicationAction.LAUNCH_WEBSITES, null);
    } else if (itemClicked.equals(getResources().getString(R.string.clubs))) {
        activity.perform(ApplicationAction.LAUNCH_ORGANIZATIONS, null);
    } else if (itemClicked.equals(getResources().getString(R.string.foodRatings))) {
        activity.perform(ApplicationAction.LAUNCH_RATINGS, null);
    } else if (itemClicked.equals(getResources().getString(R.string.info))) {
        activity.perform(ApplicationAction.LAUNCH_INFO_PAGE, null);
    } else if (itemClicked.equals(getResources().getString(R.string.map))) {
        activity.perform(ApplicationAction.LAUNCH_MAPS, null);
    } else
        Toast.makeText(getActivity(), "Not yet implemented", Toast.LENGTH_SHORT).show();
}