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:de.uni_weimar.m18.anatomiederstadt.LevelListFragment.java

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

    /*/* ww  w .  jav a2s .c om*/
    String sortOrder = LevelContractOLD.LevelEntry.COLUMN_PATH + " ASC";
    Uri levelUri = LevelContractOLD.LevelEntry.CONTENT_URI;
    Cursor cur = getActivity().getContentResolver().query(levelUri, null, null, null, sortOrder);
    mLevelAdapter = new LevelAdapter(getActivity(), cur, 0);
    */
    String sortOrder = LevelColumns.BASE_PATH + " ASC";
    Uri levelUri = LevelColumns.CONTENT_URI;
    Cursor cur = getActivity().getContentResolver().query(levelUri, null, null, null, sortOrder);
    mLevelAdapter = new LevelListAdapter(getActivity(), cur, 0);

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

    ListView listView = (ListView) rootView.findViewById(R.id.listview_levels);
    listView.setAdapter(mLevelAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // CursorAdapter returns a cursor at the correct position for getItem()
            // if it cannot seek to that position
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            long idx = cursor.getLong(cursor.getColumnIndex(LevelColumns._ID));
            Log.v(LOG_TAG, "OnItemClickListener id: " + Long.toString(idx));
            //Log.v(LOG_TAG, "Uri to intent: " + LevelContractOLD.LevelEntry.buildLevelsUri(idx));
            Uri uri = ContentUris.withAppendedId(LevelColumns.CONTENT_URI, idx);
            Log.v(LOG_TAG, "Uri to intent: " + uri);
            if (cursor != null) {
                Intent intent = new Intent(getActivity(), LevelPrepareActivity.class).setData(uri
                /* LevelContractOLD.LevelEntry.buildLevelsUri(idx) */);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                startActivity(intent);
            }
        }
    });

    return rootView;

}

From source file:com.doomy.decode.ScanActivity.java

@Override
public void onItemClick(AdapterView<?> listview, View v, int position, long id) {
    Scan myContact = (Scan) listview.getItemAtPosition(position);

    String myFormat = myContact.getFormat().toString();
    String myContent = myContact.getContent().toString();

    DialogFragment mFragment = ResultDialogFragment.newInstance(myFormat, myContent, false, this);
    mFragment.show(ScanActivity.this.getFragmentManager(), "result");
}

From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WRegisterFaceRecognitionDataFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mAdapter = new ListAdapter(getActivity(), -1);
    View root = inflater.inflate(R.layout.setting_recognize, null);
    mName = (EditText) root.findViewById(R.id.input_name);
    mRegister = (Button) root.findViewById(R.id.register_face_recognize);
    mRegister.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  .  ja v  a  2 s . c  o m*/
        public void onClick(View view) {
            registerFaceRecognitionData();
        }
    });
    mUnregister = (Button) root.findViewById(R.id.unregister_face_recognize);
    mUnregister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            unregisterFaceRecognitionData();
        }
    });
    mListView = (ListView) root.findViewById(R.id.recoglist);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final String name = (String) parent.getItemAtPosition(position);
            mName.setText(name);
        }
    });
    root.findViewById(R.id.search_c2w).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            initListView();
        }
    });
    return root;
}

From source file:akhil.alltrans.AppListFragment.java

@SuppressLint("WorldReadableFiles")
@Override//from  www .j a v a 2s  .  co m
public void onStart() {
    super.onStart();
    context = this.getActivity();
    //noinspection deprecation,deprecation
    BackupSharedPreferences.backupSharedPreferences(this.getActivity());
    settings = this.getActivity().getSharedPreferences("AllTransPref", MODE_WORLD_READABLE);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);

    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean("com.astroframe.seoulbus", true);
    editor.putBoolean("com.nhn.android.nmap", true);
    editor.putBoolean("com.kakao.taxi", true);
    editor.putBoolean("com.fineapp.yogiyo", true);
    editor.putBoolean("com.cgv.android.movieapp", true);
    editor.putBoolean("com.wooricard.smartapp", true);
    editor.putBoolean("com.google.android.talk", true);
    editor.putBoolean("com.ebay.global.gmarket", true);
    editor.putBoolean("com.foodfly.gcm", true);
    editor.putBoolean("com.ktcs.whowho", true);
    editor.putString("SubscriptionKey", "65044997b4194b8f8c181a15166fcb46");
    //        editor.putBoolean("EnableYandex", true);
    //        editor.putString("SubscriptionKey", "trnsl.1.1.20170118T002434Z.95dd93bf09dbc8d4.04554b9aac2c1bcfee17ee76bc9979236ea2c2d4");
    editor.apply();

    //noinspection ConstantConditions
    listview = (NestedScrollingListView) getView().findViewById(R.id.AppsList);

    new PrepareAdapter().execute();

    listview.setChoiceMode(NestedScrollingListView.CHOICE_MODE_MULTIPLE);
    listview.setNestedScrollingEnabled(true);
    listview.setFastScrollEnabled(true);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ApplicationInfo curApp = (ApplicationInfo) parent.getItemAtPosition(position);
            utils.debugLog(curApp.packageName);
            LocalPreferenceFragment localPreferenceFragment = new LocalPreferenceFragment();
            localPreferenceFragment.applicationInfo = curApp;
            context.getSupportFragmentManager().beginTransaction()
                    .replace(R.id.toReplace, localPreferenceFragment).addToBackStack(null)
                    .commitAllowingStateLoss();
        }
    });
    fireBaseAnalytics();
}

From source file:com.github.mobile.ui.gist.GistFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object item = parent.getItemAtPosition(position);
    if (item instanceof GistFile)
        startActivity(GistFilesViewActivity.createIntent(gist, position - 1));
}

From source file:org.linphone.ContactsFragment.java

@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
    Contact contact = (Contact) adapter.getItemAtPosition(position);
    if (editOnClick) {
        editConsumed = true;/* ww  w.  j ava2 s.co m*/
        LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
    } else {
        lastKnownPosition = contactsList.getFirstVisiblePosition();
        LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
    }
}

From source file:com.google.firebase.samples.apps.mlkit.java.LivePreviewActivity.java

@Override
public synchronized void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    // An item was selected. You can retrieve the selected item using
    // parent.getItemAtPosition(pos)
    selectedModel = parent.getItemAtPosition(pos).toString();
    Log.d(TAG, "Selected model: " + selectedModel);
    preview.stop();/*from  w  w  w .  j a  va 2 s  .c o  m*/
    if (allPermissionsGranted()) {
        createCameraSource(selectedModel);
        startCameraSource();
    } else {
        getRuntimePermissions();
    }
}

From source file:com.developers.pnp.lilly.app.PlacesFragment.java

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

    // The PlacesAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mPlacesAdapter = new PlacesAdapter(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.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mPlacesAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override// ww  w . j  a v a2 s  .c o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.

            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                ((Callback) getActivity()).onItemSelected(
                        PlacesContract.PlaceEntry.buildPlaceFromGoogleID(cursor.getString(COL_PLACE_REF_ID)));
            }

            mPosition = position;
        }
    });

    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:net.illusor.swipeplayer.fragments.FolderBrowserFragment.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    //if selected directory has subfolders with music - navigate there
    //if not - inflate the playlist with the contents of the directory
    AudioFile selected = (AudioFile) adapterView.getItemAtPosition(i);
    if (selected.hasSubDirectories())
        this.getSwipeActivity().openMediaDirectory(selected);
    else/*from   ww  w .  j  ava  2 s  . c om*/
        this.getSwipeActivity().playMediaDirectory(selected);
}

From source file:ca.qc.bdeb.info.horus.ForecastFragment.java

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

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    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.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mForecastAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from   ww  w.  j  av a2 s .  co m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}