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.github.riotopsys.malforandroid2.fragment.AbstractListFragment.java

@Override
public void onItemClick(AdapterView<?> view, View arg1, int position, long arg3) {
    BaseRecord item = (BaseRecord) view.getItemAtPosition(position);
    if (item instanceof AnimeRecord) {
        bus.post(new AnimeChangeDetailViewRequest(item.id));
    } else {//from  ww  w.  ja v  a 2  s.  c  om
        bus.post(new MangaChangeDetailViewRequest(item.id));
    }
}

From source file:com.laevatein.internal.ui.AlbumListFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    AlbumListViewHelper.callOnSelect(mListener, (Cursor) parent.getItemAtPosition(position));
    AlbumListViewHelper.setCheckedState(this, position);
    mCollection.setStateCurrentSelection(position);
}

From source file:sx.tfr.openraid.Activity.EventList.java

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

    //Get any information from the parent activity
    Intent intent = getIntent();/*w  w w  . j a  v a2  s  . c  o m*/
    Bundle extras = intent.getExtras();

    JsonUtil.clean();
    eventsArrayList = JsonUtil.fromString_toEvent(extras.getString("json"));

    //Trigger the list elements to be created
    mainListView = (ListView) findViewById(R.id.listView);
    mainListView.setAdapter(new EventListAdapter(this.getApplicationContext(), eventsArrayList));

    mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Event event = (Event) parent.getItemAtPosition(position);
            Intent intent = new Intent(EventList.this, EventView.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("event", event);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });
}

From source file:com.vandalsoftware.example.single.android.MainFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (getActivity() != null) {
        final CarPart carPart = (CarPart) parent.getItemAtPosition(position);
        final Intent intent = new Intent(getActivity(), InfoActivity.class);
        intent.putExtra(InfoActivity.EXTRA_CAR_PART, carPart);
        startActivity(intent);/*  w ww .j a  v a  2  s.c  om*/
    }
}

From source file:it_minds.dk.eindberetningmobil_android.views.MissingTripActivity.java

public void refreshData() {
    MissingTripsAdapter adapter = new MissingTripsAdapter(this);
    adapter.addAll(MainSettings.getInstance(this).getDrivingReports());
    listView.setAdapter(adapter);//from  w  ww . j  av a  2 s  . co m
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final SaveableReport report = (SaveableReport) parent.getItemAtPosition(position);
            ConfirmationDialog dialog = new ConfirmationDialog(MissingTripActivity.this,
                    getString(R.string.report_title), getString(R.string.missing_report_dialog_message),
                    getString(R.string.send), getString(R.string.delete), null, new ResultCallback<Boolean>() {
                        @Override
                        public void onSuccess(Boolean result) {
                            trySend(report);
                        }

                        @Override
                        public void onError(Exception error) {
                            MainSettings.getInstance(MissingTripActivity.this).removeSavedReport(report);
                            refreshData();
                        }
                    });
            dialog.setCanCancel(true);
            dialog.showDialog();
        }
    });
}

From source file:de.grobox.liberario.FavTripsFragment.java

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

    // remove trip on long click
    getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override// www  . ja v a2s  .  co m
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final FavTrip trip = (FavTrip) parent.getItemAtPosition(position);

            new AlertDialog.Builder(getActivity())
                    .setMessage(getActivity().getResources().getString(R.string.clear_fav_trips))
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            FavFile.unfavTrip(getActivity(), trip);
                            adapter.remove(trip);
                        }
                    }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    }).show();
            return true;
        }
    });
}

From source file:org.jboss.aerogear.crypto.android.demo.fragments.ListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.list, null);

    ArrayAdapter<Credential> adapter = new ArrayAdapter(getActivity(), simple_list_item_1, credentials);

    ListView listView = (ListView) view.findViewById(android.R.id.list);
    listView.setAdapter(adapter);//from   w ww . j  a va 2 s  . c  o m

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            Credential credential = (Credential) adapterView.getItemAtPosition(position);

            CryptoActivity activity = (CryptoActivity) getActivity();
            activity.displayInfo(credential);
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
            final Credential credential = (Credential) adapterView.getItemAtPosition(position);

            new AlertDialog.Builder(getActivity()).setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle(getString(R.string.delete)).setMessage(getString(R.string.delete_confirmation))
                    .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            CryptoActivity activity = (CryptoActivity) getActivity();
                            activity.delete(credential);
                        }
                    }).setNegativeButton(getString(R.string.no), null).show();
            return false;
        }
    });

    return view;
}

From source file:com.lwz.searchbar.demo.MainActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object itemData = parent.getItemAtPosition(position);
    if (itemData instanceof Bank) {
        Toast.makeText(this, ((Bank) itemData).name, Toast.LENGTH_SHORT).show();
    }/*  w w  w  .j  a  va  2  s  . co  m*/
}

From source file:com.example.android.activityscenetransitionbasic.MainActivity.java

/**
 * Called when an item in the {@link android.widget.GridView} is clicked. Here will launch the
 * {@link DetailActivity}, using the Scene Transition animation functionality.
 *//*ww w.  java2 s  .com*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    Item item = (Item) adapterView.getItemAtPosition(position);

    // Construct an Intent as normal
    Intent intent = new Intent(this, DetailActivity.class);
    intent.putExtra(DetailActivity.EXTRA_PARAM_ID, item.getId());

    // BEGIN_INCLUDE(start_activity)
    /**
     * Now create an {@link android.app.ActivityOptions} instance using the
     * {@link ActivityOptionsCompat#makeSceneTransitionAnimation(Activity, Pair[])} factory
     * method.
     */
    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this,

            // Now we provide a list of Pair items which contain the view we can transitioning
            // from, and the name of the view it is transitioning to, in the launched activity
            new Pair<View, String>(view.findViewById(R.id.imageview_item),
                    DetailActivity.VIEW_NAME_HEADER_IMAGE),
            new Pair<View, String>(view.findViewById(R.id.textview_name),
                    DetailActivity.VIEW_NAME_HEADER_TITLE));

    // Now we can start the Activity, providing the activity options as a bundle
    ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
    // END_INCLUDE(start_activity)
}

From source file:com.malmstein.materialanimations.activityscenetransitionbasic.TransitionActivity.java

/**
 * Called when an item in the {@link android.widget.GridView} is clicked. Here will launch the
 * {@link DetailActivity}, using the Scene Transition animation functionality.
 *//*from  w w w .j a v  a 2 s.c o  m*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    Item item = (Item) adapterView.getItemAtPosition(position);

    // Construct an Intent as normal
    Intent intent = new Intent(this, DetailActivity.class);
    intent.putExtra(DetailActivity.EXTRA_PARAM_ID, item.getId());

    // BEGIN_INCLUDE(start_activity)
    /**
     * Now create an {@link android.app.ActivityOptions} instance using the
     * {@link android.support.v4.app.ActivityOptionsCompat#makeSceneTransitionAnimation(android.app.Activity, android.support.v4.util.Pair[])} factory
     * method.
     */
    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this,

            // Now we provide a list of Pair items which contain the view we can transitioning
            // from, and the name of the view it is transitioning to, in the launched activity
            new Pair<View, String>(view.findViewById(R.id.imageview_item),
                    DetailActivity.VIEW_NAME_HEADER_IMAGE),
            new Pair<View, String>(view.findViewById(R.id.textview_name),
                    DetailActivity.VIEW_NAME_HEADER_TITLE));

    // Now we can start the Activity, providing the activity options as a bundle
    ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
    // END_INCLUDE(start_activity)
}