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.kiwiteam.nomiddleman.LargeGroupActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    int vId = parent.getId();
    switch (vId) {
    case R.id.day:
        String day = parent.getItemAtPosition(position).toString();
        ArrayList<Integer> quantities = tour.getAllTourSessionAvailability(day);

        tQty = (Spinner) findViewById(R.id.quantity);
        qAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, quantities);
        qAdapter.notifyDataSetChanged();

        qAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        tQty.setAdapter(qAdapter);/*w w w. j a  va  2s.c o m*/
        break;
    }
}

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

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

    if (mListView != null) {
        mListView.setOnItemClickListener(new ListView.OnItemClickListener() {

            @Override//from ww  w . jav  a 2 s  .  co m
            public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
                Log.d("SensorDataCollector",
                        "onActivityCreated(): Sensor ListView clicked at postion " + position);
                if (getActivity() instanceof ViewExperimentActivity) {
                    mCallback.onSensorClicked_ExperimentViewSensorListFragment(position);
                } else if (getActivity() instanceof CreateExperimentActivity) {
                    mCallback.onSensorClicked_ExperimentViewSensorListFragment(
                            (AbstractSensor) listView.getItemAtPosition(position));
                }
            }
        });
    }
}

From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    Cursor c = (Cursor) arg0.getItemAtPosition(position);
    if (c != null) {
        String title = c.getString(ACH_TITLE);
        String description = c.getString(ACH_DESCRIPTION);

        showAchievementDetails(title, description);
    }/*w w  w  .  j a va2  s . co m*/
}

From source file:com.google.android.apps.flexbox.MainActivity.java

private void initializeFlexWrapSpinner(Menu navigationMenu) {
    initializeSpinner(mFlexboxLayout.getFlexWrap(), R.id.menu_item_flex_wrap, navigationMenu,
            R.array.array_flex_wrap, new AdapterView.OnItemSelectedListener() {
                @Override/*from   w w w.ja v  a  2s .c  o m*/
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    int flexWrap = FlexboxLayout.FLEX_WRAP_NOWRAP;
                    String selected = parent.getItemAtPosition(position).toString();
                    if (selected.equals(NOWRAP)) {
                        flexWrap = FlexboxLayout.FLEX_WRAP_NOWRAP;
                    } else if (selected.equals(WRAP)) {
                        flexWrap = FlexboxLayout.FLEX_WRAP_WRAP;
                    } else if (selected.equals(WRAP_REVERSE)) {
                        flexWrap = FlexboxLayout.FLEX_WRAP_WRAP_REVERSE;
                    }
                    mFlexboxLayout.setFlexWrap(flexWrap);
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    // No op
                }
            }, new ValueToStringConverter() {
                @Override
                public String asString(int value) {
                    switch (value) {
                    case FlexboxLayout.FLEX_WRAP_NOWRAP:
                        return NOWRAP;
                    case FlexboxLayout.FLEX_WRAP_WRAP:
                        return WRAP;
                    case FlexboxLayout.FLEX_WRAP_WRAP_REVERSE:
                        return WRAP_REVERSE;
                    default:
                        return NOWRAP;
                    }
                }
            });
}

From source file:fr.forexperts.ui.ArticleListFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);//from   ww w.jav  a 2 s . com
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");
            Intent detailIntent = new Intent(getActivity(), GraphActivity.class);
            detailIntent.putExtra("code", result[0]);
            startActivity(detailIntent);
            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}

From source file:org.onebusaway.android.ui.TripPlanFragment.java

@Override
public void onResume() {
    super.onResume();

    mFromAddress = mBuilder.getFrom();/*from w  w w .j  ava 2s.  c  o m*/

    if (mFromAddress == null) {
        mFromAddress = makeAddressFromLocation();
        mBuilder.setFrom(mFromAddress);
    }

    setAddressText(mFromAddressTextArea, mFromAddress);

    mToAddress = mBuilder.getTo();

    if (mToAddress == null) {
        mToAddress = CustomAddress.getEmptyAddress();
        mBuilder.setTo(mToAddress);
    }

    setAddressText(mToAddressTextArea, mToAddress);

    boolean arriving = mBuilder.getArriveBy();

    if (mMyCalendar == null) {
        Date date = mBuilder.getDateTime();
        if (date == null) {
            date = new Date();
        }
        mMyCalendar = Calendar.getInstance();
        mMyCalendar.setTime(date);

        if (arriving) {
            mBuilder.setArrivalTime(mMyCalendar);
        } else {
            mBuilder.setDepartureTime(mMyCalendar);
        }
    }

    resetDateTimeLabels();

    String leavingChoice = getString(arriving ? R.string.trip_plan_arriving : R.string.trip_plan_leaving);
    mLeavingChoice.setSelection(mLeavingChoiceAdapter.getPosition(leavingChoice), false);

    mLeavingChoice.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            String item = (String) parent.getItemAtPosition(position);

            if (item.equals(getString(R.string.trip_plan_arriving))) {
                mBuilder.setArrivalTime(mMyCalendar);
            } else {
                mBuilder.setDepartureTime(mMyCalendar);
            }
            checkRequestAndSubmit();
        }

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

From source file:com.garage.payless.fragment.FragmentList.java

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

    DelayAutoCompleteTextView bookTitle = (DelayAutoCompleteTextView) rootView.findViewById(R.id.book_title);
    bookTitle.setThreshold(4);/*from www.j av a  2  s  . c  o  m*/
    bookTitle.setAdapter(new GoodAutoCompleteAdapter(getActivity().getApplicationContext()));
    bookTitle.setLoadingIndicator((ProgressBar) rootView.findViewById(R.id.progress_bar));
    bookTitle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            LinearLayout basketList = (LinearLayout) rootView.findViewById(R.id.basket);
            LinearLayout row = new LinearLayout(getActivity().getApplicationContext());
            row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.setOrientation(LinearLayout.HORIZONTAL);
            TextView valueTV = new TextView(getActivity().getApplicationContext());
            valueTV.setText((String) adapterView.getItemAtPosition(position));
            valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            row.addView(valueTV);
            ImageButton cancel = new ImageButton(getActivity().getApplicationContext());
            cancel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            cancel.setImageDrawable(Drawable.createFromPath("@android:drawable/ic_menu_close_clear_cancel"));
            row.addView(cancel);
            basketList.addView(row);
        }
    });
    rootView.findViewById(R.id.create_btn).setOnClickListener(this);
    return rootView;
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Function that is called when you press the add tag
 * /*from  w w w  .j ava 2  s  .  c  o m*/
 * Creates a alert dialog that gives the user the option 
 * of adding a previously added tag or entering a new tag name
 * 
 * @param view
 */
public void addTagButton(View view) {
    final EditText enterTag = new EditText(this);
    final Spinner tagSpinner = new Spinner(this);
    //Linear layout that holds enterTag and tagSpinner views
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    tagSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int position, long id) {
            enterTag.setText(parent.getItemAtPosition(position).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub      
        }
    });

    enterTag.setHint("Enter tag");
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    //get all the tags currently added to claims in application claimlist
    ArrayList<Tag> tags = ClaimListController.getTagList();
    String t[] = new String[tags.size()];
    for (int i = 0; i < tags.size(); i++) {
        t[i] = tags.get(i).getName();
    }
    //create a arrayadaptor for displaying the tagSpinner view, and set it
    ArrayAdapter<String> tagA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, t);
    tagSpinner.setAdapter(tagA);
    //add views to linear layout and set the Linear layout view as the alert dialog view 
    ll.addView(tagSpinner);
    ll.addView(enterTag);
    alert.setView(ll);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Tag tag = new Tag(enterTag.getText().toString());
            if (theClaim.getTagList().getTag(enterTag.getText().toString()) != null) {
                return;
            }
            ClaimListController.addTag(theClaim, tag);
            tagAdaptor.notifyDataSetChanged();
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    alert.show();
}

From source file:de.elanev.studip.android.app.frontend.messages.MessageComposeFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // initialize CursorLoader
    getLoaderManager().initLoader(0, mArgs, this);
    // initializing OptionsMenu and Actionbar
    setHasOptionsMenu(true);//www  . j ava 2s  . c  o m

    // fill the views with message details from the arguments if existing
    if (mUserItem != null && mMessageFlag != MESSAGE_FORWARD) {
        mAutoCompleteTextView.setText(mUserItem.getFullname());
        mAutoCompleteTextView.setTag(mUserItem);
        mAutoCompleteTextView.setEnabled(false);
    }

    // set message subject and fragment title according to the messageFlag
    if (mSubject != null) {
        switch (mMessageFlag) {
        case MESSAGE_FORWARD:
            mSubject = String.format("%s: %s", getString(R.string.message_forward_string), mSubject);
            getActivity().setTitle(TextTools.capitalizeFirstLetter(getString(R.string.forward_message)));
            break;
        case MESSAGE_REPLY:
            mSubject = String.format("%s: %s", getString(R.string.message_reply_string), mSubject);
            getActivity().setTitle(TextTools.capitalizeFirstLetter(getString(R.string.reply_message)));
            break;
        }

        mSubjectEditTextView.setText(mSubject);
    }

    if (mMessage != null)
        mMessageEditTextView.setText(String.format("\n%s %s:\n%s", getString(R.string.original_message),
                TextTools.getLocalizedAuthorAndDateString(mUserItem.getFullname(), mDate, mContext),
                Html.fromHtml(mMessage)));

    mAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {

        // set the selected item
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            UserItem item = (UserItem) parent.getItemAtPosition(position);
            mAutoCompleteTextView.setTag(item);
            mAutoCompleteTextView.setEnabled(false);
        }
    });

    mAutoCompleteTextView.setOnKeyListener(new OnKeyListener() {

        // Check if there is a valid receiver set an delete it completely
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (mAutoCompleteTextView.getTag() != null) {
                    mAutoCompleteTextView.setTag(null);
                    mAutoCompleteTextView.setText("");
                }
            }
            return false;
        }
    });

    if (TextUtils.isEmpty(mAutoCompleteTextView.getText())) {
        mAutoCompleteTextView.requestFocus();
    } else if (TextUtils.isEmpty(mSubjectEditTextView.getText())) {
        mSubjectEditTextView.requestFocus();
    } else {
        mMessageEditTextView.requestFocus();
        mMessageEditTextView.setSelection(0);
    }

}

From source file:com.example.android.cupboard.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the units for the amount of food.
 *///  www  .  j a  v a 2  s  .  co  m
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 unitsSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_units_options,
            android.R.layout.simple_spinner_item);

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

    // Apply the adapter to the spinner
    mUnitsSpinner.setAdapter(unitsSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mUnitsSpinner.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.units_g))) {
                    mUnit = FoodEntry.UNITS_G;
                } else if (selection.equals(getString(R.string.units_kg))) {
                    mUnit = FoodEntry.UNITS_KG;
                } else if (selection.equals(getString(R.string.units_ml))) {
                    mUnit = FoodEntry.UNITS_ML;
                } else if (selection.equals(getString(R.string.units_l))) {
                    mUnit = FoodEntry.UNITS_L;
                } else {
                    mUnit = FoodEntry.UNITS_UNKNOWN;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mUnit = FoodEntry.UNITS_UNKNOWN;
        }
    });
}