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:br.pro.menotti.opus.pt.DisplayPoints.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = getIntent();/*from w ww  .ja v  a  2  s.co m*/
    final int book = intent.getIntExtra("book", 0);
    int chapter = intent.getIntExtra("chapter", 0);
    final String search_key = intent.getStringExtra("search_key");
    final boolean favorites = intent.getBooleanExtra("favorites", false);

    db = new SQLiteHelper(this);
    db.openDataBase();
    //      final String book_name = db.getBook(book).toString();

    ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setFastScrollEnabled(true);

    if (favorites) {
        setTitle(getString(R.string.display_favorites));
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getFavoritePoints();
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    } else if (search_key != null) {
        setTitle(getString(R.string.display_search) + ": " + search_key);
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getPoints(search_key);
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    } else {
        setTitle(db.getBook(book) + ": " + db.getChapter(book, chapter));
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getBookPoints(book, chapter);
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    }

    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            db = new SQLiteHelper(getBaseContext());
            db.openDataBase();
            BookPoint bp = (BookPoint) parent.getItemAtPosition(position);
            DialogFragment newFragment = new DialogPoint(bp, favorites);
            newFragment.show(getSupportFragmentManager(), bp.toString());
            db.close();
            return true;
        }
    });

    db.close();
}

From source file:com.google.android.demos.rss.app.ChannelActivity.java

public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Object item = l.getItemAtPosition(position);
    Cursor cursor = mAdapter.getCursor();
    if (item != null && item == cursor) {
        showDialog(DIALOG_ITEM);//from ww  w  . java  2  s  .com

        // Assign item data to dialog from cursor
        ChannelAdapter.setItemData(mItemDialog, cursor);

        // Scroll to top of item content
        mItemDialog.scrollToTop();
    }
}

From source file:de.uni_koblenz_landau.apow.EncounterListFragment.java

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

    View view = inflater.inflate(R.layout.encounter_list_fragment, container, false);

    // Create UI references.
    mListView = (ListView) view.findViewById(R.id.encounter_list_fragment_listview);
    mListView.setEmptyView(view.findViewById(android.R.id.empty));
    mListView.getEmptyView().setVisibility(ListView.GONE);
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from  w w  w .  j  av a2 s .  com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListViewItem item = (ListViewItem) parent.getItemAtPosition(position);
            Intent intent = new Intent(getActivity(), ObsListActivity.class);
            intent.putExtra(ObsListFragment.ARG_ENCOUNTER_ID, (int) id);
            intent.putExtra(ObsListFragment.ARG_TITLE, item.getField2());
            getActivity().startActivity(intent);
        }
    });

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        mEncounters = savedInstanceState.getParcelableArrayList(ARG_ENCOUNTERS);
        EncounterAdapter adapter = new EncounterAdapter(this.getActivity(), mEncounters);
        mListView.setAdapter(adapter);
    } else {
        loadEncounters();
    }

    return view;
}

From source file:com.uwetrottmann.movies.ui.MoviesFragment.java

@TargetApi(16)
@Override//from w  w w .j a v  a2  s . c o  m
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    Movie movie = (Movie) parent.getItemAtPosition(position);
    if (movie != null && movie.id != null) {
        // display details about this movie in a new activity
        Intent i = new Intent(getActivity(), MovieDetailsActivity.class);
        i.putExtra(MovieDetailsFragment.InitBundle.TMDBID, movie.id);
        if (AndroidUtils.isJellyBeanOrHigher()) {
            Bundle options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight())
                    .toBundle();
            getActivity().startActivity(i, options);
        } else {
            startActivity(i);
        }
    }
}

From source file:com.skubit.android.transactions.TransactionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.wallet_transactions_fragment, null);
    TextView balanceLabel = (TextView) view.findViewById(R.id.wallet_balance_label);
    balanceLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    mBalance = (TextView) view.findViewById(R.id.wallet_balance);

    ListView list = (ListView) view.findViewById(R.id.list);
    list.setAdapter(mAdapter);//from w  w  w. j a  v  a  2  s  . c o  m

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            TransactionDto transactionDto = (TransactionDto) adapter.getItemAtPosition(position);
            ObjectMapper mapper = new ObjectMapper();
            String value;
            try {
                value = mapper.writeValueAsString(transactionDto);
                startActivity(TransactionDetailsActivity.newIntent(value, getActivity().getPackageName()));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

    });

    return view;
}

From source file:org.rssin.android.NavigationDrawerManageFiltersFragment.java

/**
 * Setup listeners for the list items/*from   w w  w .  j a v a 2 s .c o m*/
 */
private void setupListeners() {
    onFilterClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Filter item = (Filter) parent.getItemAtPosition(position);
            openFilterSettings(item);
        }
    };

    filtersView.setOnItemClickListener(onFilterClickListener);
}

From source file:com.lillicoder.newsblurry.feeds.FeedsListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    this._feedsList.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from w  w w. j  a v a 2  s .  co  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            IFeed feed = (IFeed) parent.getItemAtPosition(position);
            if (feed.hasChildren()) {
                // Load next fragment list for the child feeds.
                Intent childFeeds = new Intent(FeedsListFragment.this.getActivity(), FeedsActivity.class);
                childFeeds.putExtra(FeedsActivity.INTENT_FEED_TO_DISPLAY, feed);

                FeedsListFragment.this.startActivity(childFeeds);
            } else {
                // Feed is an actual feed, display stories.
                Intent stories = new Intent(FeedsListFragment.this.getActivity(), StoriesActivity.class);
                stories.putExtra(StoriesActivity.INTENT_FEED_TO_DISPLAY, feed);

                FeedsListFragment.this.startActivity(stories);
            }
        }
    });

    // Check for passed feed to display. If it is present, we will
    // display the master list of feeds for the user.
    IFeed feed = this.getFeed();
    if (feed != null)
        this.updateList(feed.getChildren());
    else
        this.fetchFeeds();
}

From source file:com.jbirdvegas.mgerrit.ChangelogFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mParent = this.getActivity();
    mRequestQueue = Volley.newRequestQueue(mParent);

    mViewSwitcher = (ViewSwitcher) mParent.findViewById(R.id.vs_changelog_card);
    if (mViewSwitcher.getDisplayedChild() != 0)
        mViewSwitcher.showPrevious();//w  w  w.ja v a  2  s. com

    mUpdatesList = (Spinner) mParent.findViewById(R.id.changelog);
    mSaveBtn = (ImageView) mParent.findViewById(R.id.goo_download_zip_button);
    mSaveBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSaveClicked();
        }
    });

    mUpdatesList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            GooFileObject buildObject = (GooFileObject) parent.getItemAtPosition(position);
            GooFileObject previousBuild = null;
            if (position + 1 < parent.getCount()) {
                previousBuild = (GooFileObject) parent.getItemAtPosition(position + 1);
            }
            ((ChangelogActivity) mParent).onBuildSelected(previousBuild, buildObject);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // Not used
        }
    });

    findDates();
}

From source file:com.afg.MngProductContentProvider.Fragments.MultiSelectList_Fragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mList = getListView();// www  . ja va2s . c o  m
    mList.setAdapter(mAdapter);
    mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    //final MultiChoiceListener mcl = new MultiChoiceListener(getContext(), mChoicePresenteR);
    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
            Bundle potatoe = new Bundle();
            potatoe.putParcelable(PRODUCT_KEY, (Product) parent.getItemAtPosition(i));
            mCallback.showManageProduct(potatoe);
        }
    });

    mList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            //getListView().setItemChecked(i, mcl.isPosition(i));
            return true;
        }
    });
}

From source file:sysnetlab.android.sdc.ui.fragments.ExperimentSensorSelectionFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d("SensorDataCollector", "ExperimentSensorSelectionFragment::onActivityCreated() called.");

    final CheckBox checkAll = ((CheckBox) mView.findViewById(R.id.checkbox_check_all));
    checkAll.setOnClickListener(new CheckBox.OnClickListener() {
        @Override//ww  w  .  j  a v  a  2 s.c o  m
        public void onClick(View v) {
            final boolean checked = checkAll.isChecked();
            mCallback.onBtnClearClicked_ExperimentSensorSelectionFragment(checked);
        }
    });

    // ((ListView) mView.findViewById(R.id.layout_sensor_list))
    mListView.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            mCallback.onSensorClicked_ExperimentSensorSelectionFragment(
                    (AbstractSensor) listView.getItemAtPosition(position));
        }
    });
}