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.learnNcode.mediachooser.fragment.BucketImageFragment.java

private void init() {
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
    Cursor cursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            PROJECTION_BUCKET, null, null, orderBy + " DESC");
    ArrayList<BucketEntry> buffer = new ArrayList<BucketEntry>();
    try {//  w ww.  j  a  va2 s . c om
        while (cursor.moveToNext()) {
            BucketEntry entry = new BucketEntry(cursor.getInt(INDEX_BUCKET_ID),
                    cursor.getString(INDEX_BUCKET_NAME), cursor.getString(INDEX_BUCKET_URL));

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

        bucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, false);
        mGridView.setAdapter(bucketAdapter);

        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 {
        cursor.close();
    }
}

From source file:pw.dedominic.airc.fragment.ChannelFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {

    View v = inflater.inflate(R.layout.fragment_channel, null);
    channelList = (ListView) v.findViewById(R.id.channel_list);

    channelList.setAdapter(ChannelAdapter.newInstance(getActivity(),
            (ArrayList<String>) getArguments().getSerializable("channelList")));
    channelList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from   ww w  .j a  v a2 s .c o m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String channel = (String) parent.getItemAtPosition(position);
            callback.channelSelected(channel);
        }
    });
    channelList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final String channel = (String) parent.getItemAtPosition(position);
            if (channel.equals(ChannelAdapter.ADD_CHAN_VALUE) || channel.equals(ChannelAdapter.STATUS_VALUE)
                    || channel.equals(ChannelAdapter.NOT_CONNECT))
                return true;

            AlertDialog.Builder builder = new AlertDialog.Builder((Context) getActivity());
            builder.setTitle("Remove Channel " + channel + "?");
            // Set up the buttons
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    callback.channelRemoved(channel);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            builder.show();
            return true;
        }
    });
    return v;
}

From source file:com.learnNcode.mediachooser.fragment.BucketVideoFragment.java

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

            if (!buffer.contains(entry)) {
                buffer.add(entry);
            }
        }
        mBucketAdapter = new BucketGridAdapter(getActivity(), 0, buffer, true);
        mBucketAdapter.bucketVideoFragment = this;
        mGridView.setAdapter(mBucketAdapter);

        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 {
        cursor.close();
    }
}

From source file:csms19.inapp.msg.customgallery.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  w w . j a  v a 2 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, 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(), Activity_homecustomgallery.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.uet.trungthao.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//www  .  j a v a2  s . c o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(i);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                Intent intent = new Intent(getActivity(), DetailActivity.class);
                intent.setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting,
                        cursor.getLong(COL_WEATHER_DATE)));
                startActivity(intent);
            }
        }
    });

    return rootView;
}

From source file:com.survivingwithandroid.weather.settings.CityFinderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cityfinder_layout);
    AutoCompleteTextView edt = (AutoCompleteTextView) this.findViewById(R.id.edtCity);
    CityAdapter adpt = new CityAdapter(this, null);
    edt.setAdapter(adpt);/*from w w w  . j  ava 2s.c o m*/
    getActionBar().setDisplayHomeAsUpEnabled(true);

    edt.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CityResult result = (CityResult) parent.getItemAtPosition(position);
            SharedPreferences sharedPref = PreferenceManager
                    .getDefaultSharedPreferences(CityFinderActivity.this);
            //Log.d("SwA", "WOEID [" + result.getWoeid() + "]");
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("woeid", result.getWoeid());
            editor.putString("cityName", result.getCityName());
            editor.putString("country", result.getCountry());
            editor.commit();
            NavUtils.navigateUpFromSameTask(CityFinderActivity.this);
        }
    });

}

From source file:com.dazone.crewchat.libGallery.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  . ja va 2s  .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 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);
                getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:csms19.inapp.msg.customgallery.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 w w  .  j  av  a  2s . 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 selectImageIntent = new Intent(getActivity(), Activity_homecustomgallery.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:org.spinsuite.view.LV_Menu.java

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    super.setContentView(R.layout.v_menu);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        param = (ActivityParameter) bundle.getParcelable("Param");
    }/*from w w w  .j a va2s. c om*/
    if (param == null)
        param = new ActivityParameter();
    //   
    m_ActivityNo = param.getSFA_Menu_ID();
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    //   new Menu
    lookupMenu = new LookupMenu(getApplicationContext(), LookupMenu.MAIN_MENU, conn);
    //   
    menu = (ListView) findViewById(R.id.lv_Menu);
    //   Load Data
    load();
    //   Action Menu Loader
    loadActionMenu = new LoadActionMenu(this, false);
    //   
    menu.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            DisplayMenuItem item = (DisplayMenuItem) adapter.getItemAtPosition(position);
            param.setParent_ID(item.getSFA_Menu_ID());
            param.setActivityMenu_ID(item.getActivityMenu_ID());
            //   Load from Action
            currentOptionBundle = loadActionMenu.loadAction(item, param);
            currentMenuItem = item;
        }
    });
}

From source file:com.dazone.crewchat.libGallery.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 w  w  .jav  a  2s.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, 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();
    }
}