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:es.uniovi.imovil.fcrtrainer.HighscoresFragment.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    Exercise exercise = (Exercise) parent.getItemAtPosition(pos);
    initializeListView(exercise.getId());
}

From source file:com.liu.Account.view.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  ava  2s.c  om*/
    if (mRecents != null) {
        mRecents.addRecentEmoji(view.getContext(), ((Emojicon) parent.getItemAtPosition(position)));
    }
}

From source file:org.mythdroid.fragments.RecListFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> adapter, View item, int pos, long itemid) {
    Globals.curProg = (Program) adapter.getItemAtPosition(pos);
    activity.checkedIndex = pos;/*from w w  w  . ja  v  a  2s  .c o  m*/
    activity.nextActivity = TVRemote.class;
    activity.showDialog(Recordings.FRONTEND_CHOOSER);
    return true;
}

From source file:tv.acfun.video.fragment.FavoritesFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = parent.getItemAtPosition(position);
    if (o != null && o instanceof Content) {

        Content c = (Content) o;//from   w  w  w  .j  a  v a2  s . c o m
        if (mActivity instanceof HomeActivity) {
            boolean isArticleChannel = ((HomeActivity) mActivity).isArticleChannel(c.channelId);
            if (isArticleChannel) {
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("ac://ac" + c.aid));
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                    AcApp.area63Alert(mActivity);
                }
                return;
            }
        }
        DetailsActivity.start(mActivity, c.toVideo());
    }
}

From source file:com.zzx.photo.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 {//  ww  w  .j  av a2s . 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)) {
                File file = new File(entry.bucketUrl);
                String[] strings = file.getParentFile().list(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String filename) {
                        // TODO Auto-generated method stub
                        return filename.endsWith(".jpg") || filename.endsWith(".jpeg")
                                || filename.endsWith(".png");
                    }
                });
                if (strings != null)
                    entry.count = strings.length;
                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(), ImageGalleryActivity.class);
                selectImageIntent.putExtra("name", bucketEntry.bucketName);
                selectImageIntent.putExtra("bucketId", bucketEntry.bucketId + "");
                selectImageIntent.putExtra("image", true);
                selectImageIntent.putExtra("isFromBucket", true);
                getActivity().startActivityForResult(selectImageIntent,
                        MediaChooserConstants.BUCKET_SELECT_IMAGE_CODE);

            }
        });

    } finally {
        mCursor.close();
    }
}

From source file:udatraining.dyomin.com.udaproj1.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);
    mForecastAdapter.setmUseTodayLayout(mUseTodayLayout);
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  w  w  w. j a  va  2 s  . com
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                Uri weatherLocationWithDateUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                        locationSetting, cursor.getLong(ForecastFragment.COL_WEATHER_DATE));
                callback = (Callback) getActivity();
                callback.onItemSelected(weatherLocationWithDateUri);
            }
            mPosition = position;
        }
    });
    if (null != savedInstanceState && savedInstanceState.containsKey(LIST_POSITION)) {
        mPosition = savedInstanceState.getInt(LIST_POSITION);
    }
    return rootView;
}

From source file:com.example.demo_highlights.slidingmenu.fragment.PageFragment1.java

@Override
public void onItemClick(AdapterView<?> listview, View view, int position, long id) {
    // TODO Auto-generated method stub
    Map<String, Object> map = (Map<String, Object>) listview.getItemAtPosition(position);

    Intent intent = (Intent) map.get("intent");
    startActivity(intent);//from   w  ww . ja  v  a  2 s .  c  o m
    showAni(position);

}

From source file:com.mintplex.oeffioptimizer.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    autoComplete = (AutoCompleteTextView) view.findViewById(R.id.fragment_main_autocomplete);
    autoCompleteButton = (Button) view.findViewById(R.id.fragment_main_autocomplete_button);
    abfahrtComplete = (AutoCompleteTextView) view.findViewById(R.id.fragment_main_abfahrt_autocomplete);
    abfahrtButton = (Button) view.findViewById(R.id.fragment_main_abfahrt_autocomplete_button);

    try {//w w w. j  av  a 2 s  .  com
        DatabaseHelper helper = OpenHelperManager.getHelper(getActivity(), DatabaseHelper.class);
        Dao<Haltestellen, Integer> haltestellenDao = helper.getHaltestellenDao();
        List<Haltestellen> list = haltestellenDao.queryForAll();
        autoComplete.setAdapter(new ArrayAdapter<Haltestellen>(getActivity(),
                android.R.layout.simple_dropdown_item_1line, list));
        abfahrtComplete.setAdapter(new ArrayAdapter<Haltestellen>(getActivity(),
                android.R.layout.simple_dropdown_item_1line, list));

    } catch (Exception e) {
        Log.w("Reading stops failed", e);
    }

    autoComplete.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            selected = (Haltestellen) arg0.getItemAtPosition(arg2);
            autoCompleteButton.setEnabled(true);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            selected = null;
            autoCompleteButton.setEnabled(false);
        }
    });

    autoComplete.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            selected = (Haltestellen) arg0.getItemAtPosition(arg2);
            autoCompleteButton.setEnabled(true);

        }
    });

    abfahrtComplete.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            abfahrt = (Haltestellen) adapterView.getItemAtPosition(i);
            abfahrtButton.setEnabled(true);
        }
    });
    autoCompleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            HaltestellenActivity.start(getActivity(), selected.id);
        }
    });
    abfahrtButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AbfahrtenActivity.start(getActivity(), abfahrt.id);
        }
    });

    autoCompleteButton.setEnabled(false);

    recentList = (ListView) view.findViewById(R.id.fragment_main_list_recent);

    setRecentList();

    return view;

}

From source file:it.polimi.spf.app.fragments.contacts.PeopleFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    PersonInfo entry = (PersonInfo) parent.getItemAtPosition(position);
    switch (parent.getId()) {
    case R.id.contacts_people_listview:
        onFriendSelected(entry);//  www.  j  a v a  2  s  .  c  o  m
        break;
    case R.id.contacts_people_requests_listview:
        onRequestReview(entry);
        break;
    }
}

From source file:com.fachri.makers.pets.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the pet.
 *//*from w ww  .  j a v  a 2s .  com*/
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mGenderSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.gender_male))) {
                    mGender = 1; // Male
                } else if (selection.equals(getString(R.string.gender_female))) {
                    mGender = 2; // Female
                } else {
                    mGender = 0; // Unknown
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mGender = 0; // Unknown
        }
    });
}