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.mstoyanov.music_lessons.StudentsFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    switch (parent.getId()) {
    case R.id.students_list:
        Cursor cursor = (Cursor) parent.getItemAtPosition(position);
        studentId = cursor.getInt(cursor.getColumnIndex("_id"));
        String firstName = cursor.getString(cursor.getColumnIndex("firstName"));
        String lastName = cursor.getString(cursor.getColumnIndex("lastName"));
        if (dualPane) {
            studentsList.setItemChecked(position, true);
            selectedStudent = position;/*from www  .  j  a v  a 2 s .  c o  m*/

            selectionArgs[0] = String.valueOf(studentId);

            firstNameLabel.setText("First Name");
            firstNameTextView.setText(firstName);
            lastNameLabel.setText("Last Name");
            lastNameTextView.setText(lastName);

            getLoaderManager().restartLoader(STUDENT_DETAILS_LOADER, null, this);
        } else {
            Intent intent = new Intent(getActivity(), StudentDetailsActivity.class);
            intent.putExtra("STUDENT_ID", studentId);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        break;
    case R.id.student_details_list:
        Actions action = actions.get(position);
        switch (action.getType()) {
        case Actions.ACTION_CALL:
            Uri callUri = Uri.parse("tel:" + action.getData());
            Intent intent = new Intent(Intent.ACTION_CALL, callUri);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            break;
        case Actions.ACTION_EMAIL:
            intent = new Intent(Intent.ACTION_SEND);
            intent.setType("plain/text");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { action.getData() });
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            break;
        case Actions.ACTION_SMS:
            Uri smsUri = Uri.parse("sms:" + action.getData());
            intent = new Intent(Intent.ACTION_VIEW, smsUri);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        default:
            throw new IllegalArgumentException("Invalid action type: " + action.getType());
        }
    default:
        throw new IllegalArgumentException("Invalid parentId: " + parent.getId());
    }
}

From source file:org.alfresco.mobile.android.application.fragments.node.create.CreateDocumentDialogFragment.java

private View createView(LayoutInflater inflater, ViewGroup container) {
    // Configuration available ?
    ConfigService configService = ConfigManager.getInstance(getActivity()).getConfig(getAccount().getId(),
            ConfigTypeIds.CREATION);//from  w w w .  j a  v a  2 s.co m
    if (configService != null) {
        createConfigManager = new CreateConfigManager(getActivity(), configService, (ViewGroup) getRootView());
    }

    View rootView = inflater.inflate(R.layout.sdk_create_content_props, container, false);
    tv = (MaterialEditText) rootView.findViewById(R.id.content_name);
    desc = (MaterialEditText) rootView.findViewById(R.id.content_description);
    tags = (MaterialEditText) rootView.findViewById(R.id.content_tags);
    TextView tsize = (TextView) rootView.findViewById(R.id.content_size);

    if (getArguments().getSerializable(ARGUMENT_CONTENT_FILE) != null) {
        contentFile = (ContentFile) getArguments().getSerializable(ARGUMENT_CONTENT_FILE);
        tempName = contentFile.getFileName();
        tv.setText(tempName);
        tsize.setText(Formatter.formatFileSize(getActivity(), contentFile.getLength()));
        tsize.setVisibility(View.VISIBLE);
    } else {
        tsize.setVisibility(View.GONE);
    }

    tv.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            tempName = tv.getText().toString();
            if (tv.getText().length() == 0) {
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                tv.setError(null);
            } else {
                if (UIUtils.hasInvalidName(tv.getText().toString().trim())) {
                    tv.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    tv.setError(null);
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                    if (!requestInProgress) {
                        Operator.with(getActivity(), getAccount()).load(
                                new RetrieveDocumentNameRequest.Builder(getParent(), tv.getText().toString()));
                        requestCheck = false;
                        requestInProgress = true;
                    } else {
                        requestCheck = true;
                    }
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    tags.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (!((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).isEnabled()) {
                return false;
            }
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                createDocument(tv, desc);
                handled = true;
            }
            return handled;
        }
    });

    Folder parentFolder = getParent();

    Operator.with(getActivity(), getAccount())
            .load(new RetrieveDocumentNameRequest.Builder(parentFolder, contentFile.getFileName()));

    // Custom type
    if (createConfigManager != null) {
        DisplayUtils.show(rootView, R.id.types_group);
        Spinner spinner = (Spinner) rootView.findViewById(R.id.types_spinner);
        TypeAdapter adapter = new TypeAdapter(getActivity(), R.layout.row_single_line,
                createConfigManager.retrieveCreationDocumentTypeList());
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                type = (ItemConfig) parent.getItemAtPosition(pos);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // DO Nothing
            }
        });
        if (adapter.isEmpty()) {
            DisplayUtils.hide(rootView, R.id.types_group);
        }
    } else {
        DisplayUtils.hide(rootView, R.id.types_group);
    }

    return rootView;
}

From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    UIUtils.displayTitle(getActivity(), R.string.import_document_title);

    rootView = inflater.inflate(R.layout.app_import, container, false);
    if (rootView.findViewById(R.id.listView) != null) {
        initDocumentList(rootView);/*w ww .j  a v a2s.  co m*/
    } else {
        initiDocumentSpinner(rootView);
    }

    spinnerAccount = (Spinner) rootView.findViewById(R.id.accounts_spinner);
    spinnerAccount.setOnItemSelectedListener(new OnItemSelectedListener() {

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

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // Do nothing
        }
    });
    return rootView;
}

From source file:com.mattprecious.notisync.fragment.PrimaryCustomProfileListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.custom_list, container, false);

    dbAdapter = new DbAdapter(getActivity());

    broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    broadcastManager.registerReceiver(profileUpdateReceiver,
            new IntentFilter(DbAdapter.ACTION_PROFILES_UPDATED));

    listAdapter = new CustomProfileAdapter(getActivity());
    listView = (ListView) view.findViewById(R.id.list);

    View footer = inflater.inflate(R.layout.custom_footer, listView, false);
    listView.addFooterView(footer);/*from w w  w .  j  av a2 s . com*/

    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), PrimaryCustomProfileActivity.class);

            if (position < listView.getCount() - listView.getFooterViewsCount()) {
                PrimaryProfile profile = (PrimaryProfile) parent.getItemAtPosition(position);
                intent.putExtra("profile", profile);
            }

            getActivity().startActivityForResult(intent, MainActivity.REQUEST_CODE_EDIT_PROFILE);
        }
    });

    return view;
}

From source file:com.example.amit.tellymoviebuzzz.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

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

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

    // We'll call our MainActivity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*from  w w  w  .j  a va  2 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());
                // String movieSetting = Utility.getPreferredMovie(getActivity());
                String movieSetting = cursor.getString(COL_MOVIE_TYPE);

                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting,
                                cursor.getString(COL_MOVIE_SETTING)));

                startActivity(intent);
            }
        }
    });
    return rootView;
}

From source file:org.openintents.historify.ui.fragments.MainScreenFragment.java

/** Called to have the fragment instantiate its user interface view. */
@Override/*from   w w w  . j  a v  a  2  s .  c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.fragment_main_screen, container, false);

    // init list for contacts
    lstContacts = (HorizontalListView) layout.findViewById(R.id.main_screen_lstContacts);
    recentlyContactedAdapter = new RecentlyContactedAdapter(getActivity());
    lstContacts.setAdapter(recentlyContactedAdapter);

    lstContacts.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, final View view, int pos, long id) {

            view.setBackgroundResource(R.drawable.bubble);
            view.postDelayed(new Runnable() {
                public void run() {
                    view.setBackgroundDrawable(null);
                }
            }, 500);

            onContactClicked((Contact) adapterView.getItemAtPosition(pos));

        }
    });

    // init list empty view
    View viewContactListEmpty = layout.findViewById(R.id.main_screen_viewEmptyList);
    viewContactListEmpty.setVisibility(View.GONE);
    lstContacts.setEmptyView(viewContactListEmpty);

    // init buttons
    btnMore = (Button) layout.findViewById(R.id.main_screen_btnMore);

    btnFavorites = (Button) layout.findViewById(R.id.main_screen_btnFavorites);
    btnSources = (Button) layout.findViewById(R.id.btnSources);

    if (btnMore != null) {
        btnMore.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                onMoreClicked();
            }
        });

        btnFavorites.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                onFavoritesClicked();
            }
        });

        btnSources.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                onSourcesClicked();
            }
        });
    }

    return layout;
}

From source file:org.mythdroid.activities.Main.java

private Dialog createGuideDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_menu_upload_you_tube).setTitle(R.string.dispGuide).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override//w w  w .j  a  va 2 s  . c o m
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {

            String item = (String) av.getItemAtPosition(pos);
            d.dismiss();

            if (item.equals(Messages.getString("MDActivity.0"))) { //$NON-NLS-1$
                // Here
                startActivity(new Intent().setClass(ctx, Guide.class));
                return;
            }

            else if (item.equals(Messages.getString("MythDroid.23"))) { //$NON-NLS-1$
                // Choose frontend
                nextActivity = NavRemote.class;
                setExtra(Extras.GUIDE.toString());
                showDialog(FRONTEND_CHOOSER);
                return;
            }

            else {
                startActivity(
                        new Intent().putExtra(Extras.GUIDE.toString(), true).setClass(ctx, NavRemote.class));
                return;
            }

        }
    });

    return d;
}

From source file:com.example.kacyn.watchfacetest.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, mGoogleApiClient, mPeerId);

    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 w ww .jav  a2s . 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) {
                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;
}

From source file:com.alley.android.ppi.app.OverviewFragment.java

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

    mOverviewAdapter = new OverviewAdapter(getActivity(), null, 0);

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

    SupportMapFragment m = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.property_map));
    m.getMapAsync(this);

    mRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh);
    mRefreshLayout.setColorSchemeResources(R.color.primary_dark);
    mRefreshLayout.setOnRefreshListener(this);
    TypedValue typed_value = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value,
            true);//w w  w  .  j a v a  2  s . co  m
    mRefreshLayout.setProgressViewOffset(false, 0,
            getResources().getDimensionPixelSize(typed_value.resourceId));
    Log.i(OverviewFragment.LOG_TAG, "setting refreshing to true from onCreateView");
    mRefreshLayout.setRefreshing(true);
    Log.i(OverviewFragment.LOG_TAG, "setting mRefreshLayout " + mRefreshLayout);

    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mOverviewAdapter);
    View emptyView = rootView.findViewById(R.id.frame_empty);
    Log.i(LOG_TAG, "setting empty view " + emptyView);
    mListView.setEmptyView(emptyView);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(PropertyContract.PropertyEntry
                        .buildPropertyWithAddress(cursor.getString(COL_DESCRIPTION)));
            }
            mPosition = position;
        }
    });

    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:com.chenenyu.areapicker.AreaPicker.java

private void initData() {
    // ??//  ww  w  .j av  a2s  .com
    db = new DBHelper(mActivity);
    province = db.getProvinceList();

    provinceAdapter = new AreaAdapter(mActivity, province, provinceLv, cityLv, countyLv);
    // ??
    provinceAdapter.setSelectedItem(getSavedProvincePosition());
    provinceLv.setAdapter(provinceAdapter);
    provinceLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // ????
            Province current_province = (Province) parent.getItemAtPosition(position);
            selectedProvince = current_province.getName();
            areaHelper.saveCurrentProvince(selectedProvince);
            provinceAdapter.setSelectedItem(position);
            provinceAdapter.notifyDataSetChanged();
            if (getLevel() == PickLevel.PROVINCE_ONLY) {
                submit();
            } else {
                // ?
                setCityData(current_province.getCode());
            }
        }
    });
    cityAdapter = new AreaAdapter(mActivity, city, provinceLv, cityLv, countyLv);
    cityLv.setAdapter(cityAdapter);
    cityLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            City current_city = (City) parent.getItemAtPosition(position);
            selectedCity = current_city.getName();
            areaHelper.saveCurrentCity(selectedCity);
            cityAdapter.setSelectedItem(position);
            cityAdapter.notifyDataSetChanged();
            if (getLevel() == PickLevel.PROVINCE_CITY) {
                submit();
            } else {
                setCountyData(current_city.getCode());
            }
        }
    });
    countyAdapter = new AreaAdapter(mActivity, county, provinceLv, cityLv, countyLv);
    countyLv.setAdapter(countyAdapter);
    countyLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            County current_county = (County) parent.getItemAtPosition(position);
            selectedCounty = current_county.getName();
            areaHelper.saveCurrentCounty(selectedCounty);
            countyAdapter.setSelectedItem(position);
            countyAdapter.notifyDataSetChanged();
            submit();
        }
    });
}