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:us.theparamountgroup.android.inventory.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select if the shell has a hole.
 *//*from   w  ww .j  ava 2  s  .  com*/
private void setupHoleSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter holeSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_hole_options,
            android.R.layout.simple_spinner_item);

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

    // Apply the adapter to the spinner
    mHoleSpinner.setAdapter(holeSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mHoleSpinner.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.no_hole))) {
                    mHole = ShellContract.ShellEntry.HOLE;
                } else if (selection.equals(getString(R.string.hole))) {
                    mHole = ShellContract.ShellEntry.NO_HOLE;
                } else {
                    mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
        }
    });
}

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.skydrive);/*  ww w .  j  a  v a2 s  .c  om*/

    mPrevFolderIds = new Stack<String>();

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SkyDriveObject skyDriveObj = (SkyDriveObject) parent.getItemAtPosition(position);

            skyDriveObj.accept(new Visitor() {
                @Override
                public void visit(SkyDriveAlbum album) {
                    mPrevFolderIds.push(mCurrentFolderId);
                    loadFolder(album.getId());
                }

                @Override
                public void visit(SkyDrivePhoto photo) {
                    ViewPhotoDialog dialog = new ViewPhotoDialog(SkyDriveActivity.this, photo);
                    dialog.setOwnerActivity(SkyDriveActivity.this);
                    dialog.show();
                }

                @Override
                public void visit(SkyDriveFolder folder) {
                    mPrevFolderIds.push(mCurrentFolderId);
                    loadFolder(folder.getId());
                }

                @Override
                public void visit(SkyDriveFile file) {
                    Bundle b = new Bundle();
                    b.putString(JsonKeys.ID, file.getId());
                    b.putString(JsonKeys.NAME, file.getName());
                    showDialog(DIALOG_DOWNLOAD_ID, b);
                }

                @Override
                public void visit(SkyDriveVideo video) {
                    PlayVideoDialog dialog = new PlayVideoDialog(SkyDriveActivity.this, video);
                    dialog.setOwnerActivity(SkyDriveActivity.this);
                    dialog.show();
                }

                @Override
                public void visit(SkyDriveAudio audio) {
                    PlayAudioDialog audioDialog = new PlayAudioDialog(SkyDriveActivity.this, audio);
                    audioDialog.show();
                }
            });
        }
    });

    LinearLayout layout = new LinearLayout(this);
    Button newFolderButton = new Button(this);
    newFolderButton.setText("New Folder");
    newFolderButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            NewFolderDialog dialog = new NewFolderDialog(SkyDriveActivity.this);
            dialog.setOwnerActivity(SkyDriveActivity.this);
            dialog.show();
        }
    });

    layout.addView(newFolderButton);

    Button uploadFileButton = new Button(this);
    uploadFileButton.setText("Upload File");
    uploadFileButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), FilePicker.class);
            startActivityForResult(intent, FilePicker.PICK_FILE_REQUEST);
        }
    });

    layout.addView(uploadFileButton);
    lv.addHeaderView(layout);

    mPhotoAdapter = new SkyDriveListAdapter(this);
    setListAdapter(mPhotoAdapter);

    LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
    mClient = app.getConnectClient();
}

From source file:us.theparamountgroup.android.inventory.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the type of shell.
 *///from   w  ww  . j  av  a 2 s.  co  m
private void setupTypeSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter typeSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_type_options,
            android.R.layout.simple_spinner_item);

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

    // Apply the adapter to the spinner
    mTypeSpinner.setAdapter(typeSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mTypeSpinner.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.type_scallop))) {
                    mType = ShellContract.ShellEntry.TYPE_SCALLOP;
                } else if (selection.equals(getString(R.string.type_jingle))) {
                    mType = ShellContract.ShellEntry.TYPE_JINGLE;
                } else if (selection.equals(getString(R.string.type_slipper))) {
                    mType = ShellContract.ShellEntry.TYPE_SLIPPER;
                } else {
                    mType = ShellContract.ShellEntry.TYPE_SHARD;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mType = ShellContract.ShellEntry.TYPE_SCALLOP;
        }
    });
}

From source file:com.fbartnitzek.tasteemall.addentry.AddLocationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    Log.v(LOG_TAG, "onCreateView, hashCode=" + this.hashCode() + ", " + "inflater = [" + inflater
            + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
    mRootView = inflater.inflate(R.layout.fragment_add_location, container, false);

    //        mEditLocationDescription = (EditText) mRootView.findViewById(R.id.location_description);
    mEditLocationDescription = (AutoCompleteTextView) mRootView.findViewById(R.id.location_description);
    mEditLocationDescription.setThreshold(1);
    mLocationDescriptionAdapter = new CompletionLocationDescriptionAdapter(getActivity());
    mEditLocationDescription.setAdapter(mLocationDescriptionAdapter);

    mEditLocationDescription.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w  ww .  j a va  2 s .co m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(position);
            mLocation_Id = c.getLong(QueryColumns.LocationPart.CompletionQuery.COL__ID);
            mLocationId = c.getString(QueryColumns.LocationPart.CompletionQuery.COL_ID);
            Log.v(LOG_TAG, "editDescription.onItemClick Cursor with locationId=" + mLocationId);

            if (mEditLocation.getText().toString().isEmpty()) {
                String location = c.getString(QueryColumns.LocationPart.CompletionQuery.COL_FORMATTED_ADDRESS);
                if (location != null && !location.isEmpty()) {
                    mEditLocation.setText(location); // TODO: no reloading - should work
                }
            }
        }
    });

    mMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

    hideMap();
    if (mMapFragment == null) {
        Log.e(LOG_TAG, "onCreateView, MapFragment not found...");
    } else {
        mMapFragment.getMapAsync(this);
    }

    mEditLocation = (LocationAutoCompleteTextView) mRootView.findViewById(R.id.location_location);
    mEditLocation.setThreshold(1);
    mLocationAdapter = new CompletionLocationAdapter(getActivity(), true);
    mEditLocation.setAdapter(mLocationAdapter);
    //        mEditLocation = (EditText) mRootView.findViewById(R.id.location_location);
    mEditLocation.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) {
            // TODO: for now: just show it
            if (s.length() > 1) {
                hideMap();
                if (mOriginalLocationFormatted != null && mOriginalLocationFormatted.length() > 0
                        && mOriginalLocationFormatted.equals(s.toString())) {
                    // workaround: not all searches with formatted_location get address result :-p
                    showMap();
                    focusOnMap();
                    updateAndMoveToMarker();
                } else {
                    mLocationParcelable = null;
                    mLocationInput = s.toString();
                    startGeocodeService(s.toString());
                }
            }
        }
    });

    mEditLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(position);
            mLocation_Id = c.getLong(QueryColumns.LocationPart.CompletionQuery.COL__ID);
            mLocationId = c.getString(QueryColumns.LocationPart.CompletionQuery.COL_ID);
            Log.v(LOG_TAG, "editLocation.onItemClick Cursor with locationId=" + mLocationId);

            if (mEditLocationDescription.getText().toString().isEmpty()) {
                String description = c.getString(QueryColumns.LocationPart.CompletionQuery.COL_DESCRIPTION);
                if (description != null && !description.isEmpty()) {
                    mEditLocationDescription.setText(description);
                    mEditLocationDescription.setEnabled(false);
                }
            }
        }
    });

    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(STATE_LOCATION_INPUT)) {
            mLocationInput = savedInstanceState.getString(STATE_LOCATION_INPUT);
        }
        if (savedInstanceState.containsKey(STATE_LOCATION_DESCRIPTION)) {
            mLocationDescription = savedInstanceState.getString(STATE_LOCATION_DESCRIPTION);
        }
    }

    if (mLocationInput != null) {
        mEditLocation.setText(mLocationInput);
    }
    if (mLocationDescription != null) {
        mEditLocationDescription.setText(mLocationDescription);
    }

    mRootView.findViewById(R.id.location_here_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v(LOG_TAG, "here.onClick, hashCode=" + this.hashCode() + ", " + "v = [" + v + "]");
            getCurrentLocation();
        }
    });

    mListView = (ListView) mRootView.findViewById(R.id.listview_locations);
    mListView.setAdapter(mLocationListAdapter);

    if (mLocationAddresses != null && mLocationAddresses.length > 0) {
        mLocationListAdapter.addAll(mLocationAddresses);

        if (ListView.INVALID_POSITION != mPosition) {
            mListView.smoothScrollToPosition(mPosition);
            mListView.setItemChecked(mPosition, true);
        }
    }

    mListView.setOnTouchListener(new OnTouchHideKeyboardListener(this));
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPosition = position;
            Log.v(LOG_TAG, "listview.onItemClick, hashCode=" + this.hashCode() + ", " + "parent = [" + parent
                    + "], view = [" + view + "], position = [" + position + "], id = [" + id + "]");

            showMap();
            focusOnMap();

            Address address = mLocationListAdapter.getItem(mPosition);
            mLocationParcelable = Utils.getLocationFromAddress(address, mLocationInput, null);

            updateAndMoveToMarker();

            //TODO: if other...? remove mLocationId/_Id
            //TODO if addresses not equal, but nearby (same town, latLng, street ...?): ask, else remove
            // at first: same text
            if (!mLocationInput.equals(mEditLocation.getText().toString())) {
                Log.v(LOG_TAG, "listview.onItemClick, resetting mLocationId");
                mLocationId = null;
            } else {
                Log.v(LOG_TAG, "listview.onItemClick, same text - keep mLocationId");
            }

        }
    });

    createToolbar();

    return mRootView;
}

From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }// w ww.ja v a2  s .  c om
    if (view == null) {
        alphaValue = 255;
    }

    view = View.inflate(context, R.layout.brick_set_variable, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_set_variable_checkbox);

    final Brick brickInstance = this;
    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_set_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_set_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_set_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.set_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(SetVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });
    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(SetVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:me.myatminsoe.myansms.MessageListActivity.java

/**
 * {@inheritDoc}//  w w w.  j a v  a 2s  . com
 */
public final boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
        final long id) {
    final Context context = this;
    final Message m = Message.getMessage(this, (Cursor) parent.getItemAtPosition(position));
    final Uri target = m.getUri();
    final int read = m.getRead();
    final int type = m.getType();
    Builder builder = new Builder(context);
    builder.setTitle(R.string.message_options_);

    final Contact contact = conv.getContact();
    final String a = contact.getNumber();
    final String n = contact.getName();

    String[] items = longItemClickDialog;
    if (TextUtils.isEmpty(n)) {
        items[WHICH_VIEW_CONTACT] = getString(R.string.add_contact_);
    } else {
        items[WHICH_VIEW_CONTACT] = getString(R.string.view_contact_);
    }
    items[WHICH_CALL] = getString(R.string.call) + " " + contact.getDisplayName();
    if (read == 0) {
        items = items.clone();
        items[WHICH_MARK_UNREAD] = context.getString(R.string.mark_read_);
    }
    if (type == Message.SMS_DRAFT) {
        items = items.clone();
        items[WHICH_FORWARD] = context.getString(R.string.send_draft_);
    }
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Intent i;
            switch (which) {
            case WHICH_VIEW_CONTACT:
                if (n == null) {
                    i = ContactsWrapper.getInstance().getInsertPickIntent(a);
                    Conversation.flushCache();
                } else {
                    final Uri u = MessageListActivity.this.conv.getContact().getUri();
                    i = new Intent(Intent.ACTION_VIEW, u);
                }
                try {
                    MessageListActivity.this.startActivity(i);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(MessageListActivity.this, R.string.error_unknown, Toast.LENGTH_LONG).show();
                }
                break;
            case WHICH_CALL:
                MessageListActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + a)));
                break;
            case WHICH_MARK_UNREAD:
                ConversationListActivity.markRead(context, target, 1 - read);
                MessageListActivity.this.markedUnread = true;
                break;
            case WHICH_REPLY:
                MessageListActivity.this.startActivity(
                        ConversationListActivity.getComposeIntent(MessageListActivity.this, a, false));
                break;
            case WHICH_FORWARD:
                int resId;
                if (type == Message.SMS_DRAFT) {
                    resId = R.string.send_draft_;
                    i = ConversationListActivity.getComposeIntent(MessageListActivity.this,
                            MessageListActivity.this.conv.getContact().getNumber(), false);
                } else {
                    resId = R.string.forward_;
                    i = new Intent(Intent.ACTION_SEND);
                    i.setType("text/plain");
                    i.putExtra("forwarded_message", true);
                }
                CharSequence text;
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    text = Converter.convertDecNCR2Char(m.getBody());
                } else {
                    text = m.getBody();
                }
                i.putExtra(Intent.EXTRA_TEXT, text);
                i.putExtra("sms_body", text);
                context.startActivity(Intent.createChooser(i, context.getString(resId)));
                break;
            case WHICH_COPY_TEXT:
                final ClipboardManager cm = (ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    cm.setText(Converter.convertDecNCR2Char(m.getBody()));
                } else {
                    cm.setText(m.getBody());
                }
                break;
            case WHICH_VIEW_DETAILS:
                final int t = m.getType();
                Builder b = new Builder(context);
                b.setTitle(R.string.view_details_);
                b.setCancelable(true);
                StringBuilder sb = new StringBuilder();
                final String a = m.getAddress(context);
                final long d = m.getDate();
                final String ds = DateFormat.format(context.getString(R.string.DATEFORMAT_details), d)
                        .toString();
                String sentReceived;
                String fromTo;
                if (t == Calls.INCOMING_TYPE) {
                    sentReceived = context.getString(R.string.received_);
                    fromTo = context.getString(R.string.from_);
                } else if (t == Calls.OUTGOING_TYPE) {
                    sentReceived = context.getString(R.string.sent_);
                    fromTo = context.getString(R.string.to_);
                } else {
                    sentReceived = "ukwn:";
                    fromTo = "ukwn:";
                }
                sb.append(sentReceived).append(" ");
                sb.append(ds);
                sb.append("\n");
                sb.append(fromTo).append(" ");
                sb.append(a);
                sb.append("\n");
                sb.append(context.getString(R.string.type_));
                if (m.isMMS()) {
                    sb.append(" MMS");
                } else {
                    sb.append(" SMS");
                }
                b.setMessage(sb.toString());
                b.setPositiveButton(android.R.string.ok, null);
                b.show();
                break;
            case WHICH_DELETE:
                ConversationListActivity.deleteMessages(context, target, R.string.delete_message_,
                        R.string.delete_message_question, null);
                break;
            default:
                break;
            }
        }
    });
    builder.show();
    return true;
}

From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }//from  w  ww  .  ja  va 2s  .com

    view = View.inflate(context, R.layout.brick_change_variable_by, null);
    view = getViewWithAlpha(alphaValue);
    setCheckboxView(R.id.brick_change_variable_checkbox);
    final Brick brickInstance = this;

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    TextView prototypeText = (TextView) view.findViewById(R.id.brick_change_variable_prototype_view);
    TextView textField = (TextView) view.findViewById(R.id.brick_change_variable_edit_text);
    prototypeText.setVisibility(View.GONE);
    variableFormula.setTextFieldId(R.id.brick_change_variable_edit_text);
    variableFormula.refreshTextField(view);
    textField.setVisibility(View.VISIBLE);
    textField.setOnClickListener(this);

    Spinner variableSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner);
    UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject()
            .getUserVariables().createUserVariableAdapter(context, sprite);
    UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context,
            userVariableAdapter);
    userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1);

    variableSpinner.setAdapter(userVariableAdapterWrapper);

    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        variableSpinner.setClickable(true);
        variableSpinner.setEnabled(true);
    } else {
        variableSpinner.setClickable(false);
        variableSpinner.setFocusable(false);
    }

    setSpinnerSelection(variableSpinner, null);

    variableSpinner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (((Spinner) view).getSelectedItemPosition() == 0
                        && ((Spinner) view).getAdapter().getCount() == 1) {
                    NewVariableDialog dialog = new NewVariableDialog((Spinner) view);
                    dialog.addVariableDialogListener(ChangeVariableBrick.this);
                    dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                            NewVariableDialog.DIALOG_FRAGMENT_TAG);
                    return true;
                }
            }
            return false;
        }
    });

    variableSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0 && ((UserVariableAdapterWrapper) parent.getAdapter()).isTouchInDropDownView()) {
                NewVariableDialog dialog = new NewVariableDialog((Spinner) parent);
                dialog.addVariableDialogListener(ChangeVariableBrick.this);
                dialog.show(((FragmentActivity) view.getContext()).getSupportFragmentManager(),
                        NewVariableDialog.DIALOG_FRAGMENT_TAG);
            }
            ((UserVariableAdapterWrapper) parent.getAdapter()).resetIsTouchInDropDownView();
            userVariable = (UserVariable) parent.getItemAtPosition(position);
            adapterView = parent;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            userVariable = null;
        }
    });

    return view;
}

From source file:org.xingjitong.ContactsFragment.java

@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
    Contact contact = (Contact) adapter.getItemAtPosition(position);
    final Contact finalcontact = contact; //yyppdialog//yyppdial
    if (editOnClick) {
        editConsumed = true;//from  w w w. j ava 2  s. com
        LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
    } else {
        //yyppcall del begin
        /*
        //lastKnownPosition = contactsList.getFirstVisiblePosition();
        Log.v("yyppdebug", "yyppdialog 555:"+position);
        LinphoneActivity.instance().displayContact(contact,
              onlyDisplayChatAddress);
              */
        //yyppcall del end

        //---------------------------------------------------------
        //---------------------------------------------------------                  
        //String tmpmsg="?,?????????4000251688?";
        String tmpmsg = getResources().getString(R.string.calldialog_hint);

        final customdialog ad = new customdialog(getActivity());
        ad.setTitle(contact.getName());
        String tmpstr1 = ad.ToDBC(tmpmsg);
        String tmpstr2 = ad.ToDBC(tmpstr1);
        if (contact.photo != null) {
            ad.setHead(contact.photo);
        }
        //                           ad.setMessage(ad.StringFilter(tmpstr2));

        ad.setPositiveButton("?", new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ad.dismiss();
                //Toast.makeText(getActivity(), "", Toast.LENGTH_LONG).show();
                //?

                String number = finalcontact.getNum();
                String name = finalcontact.getName();
                if (getnumtype(number) == 1) {
                    Toast.makeText(getActivity(), "??!!!", Toast.LENGTH_LONG).show();
                } else if (getnumtype(number) == 2) {
                    Toast.makeText(getActivity(), "???!", Toast.LENGTH_LONG).show();
                } else if (getnumtype(number) == 3) {
                    Toast.makeText(getActivity(), "??!", Toast.LENGTH_LONG).show();
                } else if (getnumtype(number) == 0) {

                    //LinphoneActivity.instance().
                    setAddresGoToDialerAndCall(number, name, null);
                }
                //??         
                //-------------------------------
            }
        });

        ad.setNegativeButton("?", new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ad.dismiss();
                //Toast.makeText(getActivity(), "?", Toast.LENGTH_LONG).show();
            }
        });
        //---------------------------------------------------------                       
        //---------------------------------------------------------               

    }
}

From source file:com.agateau.equiv.ui.MealItemDetailActivity.java

private void setupTabs() {
    ListView fullListView = new ListView(this);
    ListView favoriteListView = new ListView(this);

    mFullListAdapter = new ProductListAdapter(this, mKernel, mProductStore.getItems());
    mFavoritesListAdapter = new ProductListAdapter(this, mKernel, mProductStore.getFavoriteItems());
    mProductStore.setOnProductStoreChangedListener(new ProductStore.OnProductStoreChangedListener() {
        @Override// ww  w.  j  a  v a2 s  . c o  m
        public void onFavoriteChanged() {
            mFavoritesListAdapter.notifyDataSetChanged();

            // Notify mFullListAdapter as well because it must update the state of its checkboxes
            mFullListAdapter.notifyDataSetChanged();
        }

        @Override
        public void onItemListChanged() {
            mFullListAdapter.notifyDataSetChanged();
        }
    });

    fullListView.setAdapter(mFullListAdapter);
    favoriteListView.setAdapter(mFavoritesListAdapter);

    AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Product product = (Product) parent.getAdapter().getItem(position);
            onSelectProduct(product);
        }
    };
    fullListView.setOnItemClickListener(listener);
    favoriteListView.setOnItemClickListener(listener);

    AdapterView.OnItemLongClickListener longClickListener = new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Product product = (Product) parent.getItemAtPosition(position);
            editCustomProduct(product);
            return true;
        }
    };

    fullListView.setLongClickable(true);
    favoriteListView.setLongClickable(true);

    fullListView.setOnItemLongClickListener(longClickListener);
    favoriteListView.setOnItemLongClickListener(longClickListener);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    ActionBarViewTabBuilder builder = new ActionBarViewTabBuilder(actionBar, viewPager);
    builder.addTab(fullListView).setText(R.string.add_meal_item_tab_all);
    builder.addTab(favoriteListView).setText(R.string.add_meal_item_tab_favorites);
}

From source file:com.example.leebeomwoo.viewbody_final.MainActivity.java

public void popupDisplay() {
    View popupView = getLayoutInflater().inflate(R.layout.menu, null);
    /**//from   w  w w  .j  a v  a2 s . c om
     * LayoutParams WRAP_CONTENT  inflate? View? ? ??
     * PopupWinidow ?.
     *
     mPopupWindow = new PopupWindow(popupView,
     RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
     */
    mPopupWindow = new PopupWindow(popupView, 1000, RelativeLayout.LayoutParams.MATCH_PARENT);
    cancel_menuBtn = popupView.findViewById(R.id.cancel_menuBtn);
    account_menuBtn = popupView.findViewById(R.id.account_menuBtn);
    body_menuBtn = popupView.findViewById(R.id.body_menuBtn);
    follow_menuBtn = popupView.findViewById(R.id.follow_menuBtn);
    food_menuBtn = popupView.findViewById(R.id.food_menuBtn);
    qna_menuBtn = popupView.findViewById(R.id.qna_Btn);
    writer_menuBtn = popupView.findViewById(R.id.writer_menuBtn);
    menu_list = popupView.findViewById(R.id.menu_list);
    menu_Scroll = popupView.findViewById(R.id.menu_Scroll);
    btn_View = popupView.findViewById(R.id.btn_View);
    main = popupView.findViewById(R.id.menu_main);
    top = popupView.findViewById(R.id.menu_top);
    menuHomeBtn = popupView.findViewById(R.id.menuBtn_home);
    //licenseBtn = popupView.findViewById(R.id.license_Btn);
    license_source = popupView.findViewById(R.id.sourceTxt);
    license_Title = popupView.findViewById(R.id.titleTxt);
    checkedTextView = popupView.findViewById(R.id.menuchecked);

    cancel_menuBtn.setOnClickListener(this);
    account_menuBtn.setOnClickListener(this);
    body_menuBtn.setOnClickListener(this);
    follow_menuBtn.setOnClickListener(this);
    food_menuBtn.setOnClickListener(this);
    qna_menuBtn.setOnClickListener(this);
    writer_menuBtn.setOnClickListener(this);
    // licenseBtn.setOnClickListener(this);
    checkedTextView.setOnClickListener(this);
    SharedPreferences preferencesCompat = getSharedPreferences("a", MODE_PRIVATE);
    int tutorial = preferencesCompat.getInt("First", 0);
    if (tutorial == 0) {
        checkedTextView.setChecked(true);
    } else {
        checkedTextView.setChecked(false);
    }
    menu_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            final String item = (String) parent.getItemAtPosition(position);
            switch (item) {
            case "? ?":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "? ":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case " ?":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case " ":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "":
                bodyTab_sub = new BodyTab_Sub();
                bodyTab_sub.setTabitemSelected(4);
                mPopupWindow.dismiss();
                break;
            case " ?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case "?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case " ?":
                followTab_sub = new FollowTab_Sub();
                followTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(2);
                mPopupWindow.dismiss();
                break;
            case "":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(3);
                mPopupWindow.dismiss();
                break;
            case "?":
                foodTab_sub = new FoodTab_Sub();
                foodTab_sub.setTabitemSelected(4);
                mPopupWindow.dismiss();
                break;
            case "?":
                writerTab_sub = new WriterTab_Sub();
                writerTab_sub.setTabitemSelected(0);
                mPopupWindow.dismiss();
                break;
            case "?":
                writerTab_sub = new WriterTab_Sub();
                writerTab_sub.setTabitemSelected(1);
                mPopupWindow.dismiss();
                break;

            }
        }

    });
    /**
     * @View anchor : anchor View    ? .
     * @ :  anchor View ?   View? ?
     * ??  ? .
     * xoff, yoff : anchor View  PopupWindow xoff x,
     * yoff y ? ??? ? ? .
     * @int xoff : -?(  ??), +?(  ??)
     * @int yoff : -?(  ??), +?(  ??)
     * achor View  ? ? .
     *  ,  ?? . ( ? ?)
     * mPopupWindow.showAsDropDown(btn_Popup, 50, 50);
     */
    mPopupWindow.setAnimationStyle(-1); // ? (-1:, 0:)

    /**
     * showAtLocation(parent, gravity, x, y)
     * @praent : PopupWindow ?? parent View 
     * View v = (View) findViewById(R.id.btn_click)?  parent ?
     * @gravity : parent View? Gravity ?  Popupwindow ? ?? .
     * @x : PopupWindow (-x, +x) ? , ??? ? ?
     * @y : PopupWindow (-y, +y) ? ?, ??? ? ?
     * mPopupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, 0, 0);
     * */
    //mPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
    /**
     * update()   PopupWindow?  ?, x, y
     * anchor View   .
     * mPopupWindow.update(anchor, xoff, yoff, width, height)(width, height);
     */
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    Log.d("popup", "display");
    mPopupWindow.showAsDropDown(popupView, Gravity.END, 0, 0);
}