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:jp.co.conit.sss.sn.ex2.fragment.MessagesFragment.java

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

    setEmptyText(getString(R.string.no_messages));

    // EmptyText????INTERNAL_EMPTY_ID??TextView?????
    // INTERNAL_EMPTY_ID?ListFragment??EmptyText?ID?????????????ListFragment???????
    TextView tx = (TextView) getView().findViewById(INTERNAL_EMPTY_ID);
    int color = getResources().getColor(R.color.settings_text_color);
    tx.setTextColor(color);//from w  w  w .j a  va 2  s. co m

    getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PushMessage pm = (PushMessage) parent.getItemAtPosition(position);
            String userData = pm.getUserData();
            Intent activityIntent = new Intent();
            if (StringUtil.isEmpty(userData) || userData.equals("null")) {
                return;
            } else {
                if (userData.startsWith("http")) {
                    activityIntent.setAction(Intent.ACTION_VIEW);
                    activityIntent.setData(Uri.parse(userData));
                } else {
                    activityIntent.setClass(mParentActivity, UserDataActivity.class);
                    activityIntent.putExtra("option", userData);
                }
            }
            startActivity(activityIntent);
        }
    });

    obtainMessagesAsync();

}

From source file:net.ustyugov.jtalk.activity.note.TemplatesActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    service = JTalkService.getInstance();
    setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark);
    setTitle(R.string.Templates);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.paged_activity);

    LinearLayout linear = (LinearLayout) findViewById(R.id.linear);
    linear.setBackgroundColor(Colors.BACKGROUND);

    LayoutInflater inflater = LayoutInflater.from(this);
    MainPageAdapter adapter = new MainPageAdapter(mPages);

    Cursor cursor = service.getContentResolver().query(JTalkProvider.ACCOUNT_URI, null,
            AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null);
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();/*ww  w .  ja v a 2 s  . c o  m*/
        do {
            final String account = cursor.getString(cursor.getColumnIndex(AccountDbHelper.JID)).trim();

            View templatePage = inflater.inflate(R.layout.list_activity, null);
            templatePage.setTag(account);
            mPages.add(templatePage);

            ListView list = (ListView) templatePage.findViewById(R.id.list);
            list.setDividerHeight(0);
            list.setCacheColorHint(0x00000000);
            list.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                    Note item = (Note) parent.getItemAtPosition(position);
                    setResult(RESULT_OK, new Intent().putExtra("text", item.getText()));
                    finish();
                }
            });

            list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                @Override
                public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
                    final Note note = (Note) parent.getItemAtPosition(position);
                    CharSequence[] items = new CharSequence[2];
                    items[0] = getString(R.string.Edit);
                    items[1] = getString(R.string.Remove);

                    AlertDialog.Builder builder = new AlertDialog.Builder(TemplatesActivity.this);
                    builder.setTitle(R.string.Actions);
                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                            case 0:
                                createDialog(account, note);
                                break;
                            case 1:
                                try {
                                    NoteManager nm = NoteManager.getNoteManager(service.getConnection(account));
                                    nm.removeNote(note);
                                    updateNotes();
                                } catch (Exception ignored) {
                                }
                                break;
                            }
                        }
                    });
                    builder.create().show();
                    return true;
                }
            });

        } while (cursor.moveToNext());
        cursor.close();
    }

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setCurrentItem(0);

    TitlePageIndicator mTitleIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
    mTitleIndicator.setTextColor(0xFF555555);
    mTitleIndicator.setViewPager(mPager);
}

From source file:com.example.hp.isun.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);
    if (mForecastAdapter.getCount() == 0) {
        Toast.makeText(getActivity(), "Ures", Toast.LENGTH_LONG).show();
    }//  w w  w  . j  a v  a2  s.  c  o  m
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

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

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

        @Override
        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());
                // Toast.makeText(getActivity(),locationSetting, Toast.LENGTH_LONG).show();
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting,
                                cursor.getLong(COL_WEATHER_DATE)));
                startActivity(intent);
            } else {
                Toast.makeText(getActivity(), "Ures", Toast.LENGTH_LONG).show();
            }
        }
    });
    return rootView;
}

From source file:app.philm.in.fragments.SideMenuFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (mCallbacks != null) {
        mCallbacks.onSideMenuItemSelected((SideMenuItem) parent.getItemAtPosition(position));
    }/*from  www . ja  v  a 2 s.  com*/
}

From source file:com.keithcassidy.finishline.LineCrossingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(onBroadcastServiceStatusReceived,
            new IntentFilter(Constants.SERVICE_STATUS_MESSAGE));

    View view = inflater.inflate(R.layout.crossing_times, container, false);

    if (dbStorage == null) {
        dbStorage = new FinishLineDataStorage(getActivity());
        dbStorage.open();/*  w  w w .  j  a  v  a2  s  .  c  o m*/
    }

    mListView = (ListView) view.findViewById(R.id.listViewCrossings);
    mListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Location l = ((Location) parent.getItemAtPosition(position));
            if (l != null) {
                sendCrossing(l);
            }
            return true;
        }
    });

    return view;

}

From source file:com.example.wmck.mysunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Context context = getActivity();

    // Create some dummy data for the ListView.  Here's a sample weekly forecast
    String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10", "Sat 6/28 - WEATHER STN - 23/18",
            "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<String>(context, // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textView, // The ID of the textview to populate.
            weekForecast);/*w ww. j a v a  2 s.co  m*/

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

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

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String weatherStr = parent.getItemAtPosition(position).toString();
            //  Toast.makeText(getActivity(),weatherStr,Toast.LENGTH_SHORT).show();
            Intent detailActivityIntent = new Intent(getActivity(), DetailActivity.class);
            detailActivityIntent.putExtra(Intent.EXTRA_TEXT, weatherStr);
            // method startActivity(Intent i) has to be called on the Context object
            startActivity(detailActivityIntent);
        }
    });

    return rootView;
}

From source file:org.alfresco.mobile.android.application.widgets.DocumentFolderPickerFragment.java

private void refreshSpinners() {
    // UPLOAD FOLDER
    Spinner spinner = (Spinner) rootView.findViewById(R.id.import_folder_spinner);
    UploadFolderAdapter upLoadadapter = null;
    if (getActivity() instanceof FolderShortcutActivity) {
        upLoadadapter = new UploadFolderAdapter(getActivity(), R.layout.row_single_line, FOLDER_SHORTCUT_LIST);
    } else {/*w  ww . j a  va  2s  . com*/
        upLoadadapter = new UploadFolderAdapter(getActivity(), R.layout.row_single_line, FOLDER_ACTIONS_LIST);
    }
    spinner.setAdapter(upLoadadapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

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

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // DO Nothing
        }
    });
    if (rootFolderTypeId == null) {
        rootFolderTypeIndex = 0;
    }
    spinner.setSelection(rootFolderTypeIndex);

    // ACTIONS ASSOCIATED
    if (getActivity() instanceof FolderShortcutActivity) {
        rootView.findViewById(R.id.actions_spinner_title).setVisibility(View.GONE);
        rootView.findViewById(R.id.actions_spinner).setVisibility(View.GONE);
        return;
    }
    spinner = (Spinner) rootView.findViewById(R.id.actions_spinner);
    ActionShortcutAdapter actionAdapter = new ActionShortcutAdapter(getActivity(), R.layout.row_single_line,
            ACTIONS_LIST);
    spinner.setAdapter(actionAdapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            actionId = (Integer) parent.getItemAtPosition(pos);
            actionIdIndex = pos;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // DO Nothing
        }
    });
    if (actionId == null) {
        actionIdIndex = 0;
    }
    spinner.setSelection(actionIdIndex);

}

From source file:color.kidpaint.com.kidpaintcolor.dialog.TextToolDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new CustomAlertDialogBuilder(mContext);
    builder.setTitle(R.string.text_tool_dialog_title);
    final View view = inflater.inflate(R.layout.dialog_text_tool, null);

    mTextEditText = (EditText) view.findViewById(R.id.text_tool_dialog_input_text);
    mTextEditText.addTextChangedListener(new TextWatcher() {
        @Override//from   w ww . j a  v  a 2s . c o  m
        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) {
            String text = mTextEditText.getText().toString();
            mOnTextToolDialogChangedListener.setText(text);
            mText = text;
        }
    });

    mFontSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_font);
    ArrayAdapter<CharSequence> fontAdapter = ArrayAdapter.createFromResource(mContext,
            R.array.text_tool_font_array, android.R.layout.simple_spinner_item);
    fontAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mFontSpinner.setAdapter(fontAdapter);

    mFontSpinner.setBackgroundColor(Color.GRAY);
    mFontSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String font = parent.getItemAtPosition(position).toString();
            mOnTextToolDialogChangedListener.setFont(font);
            mFontIndex = position;
            if (mFontSpinnerInitialized)
                hideKeyboard();
            else
                mFontSpinnerInitialized = true;
        }

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

    mUnderlinedToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_underlined);
    mUnderlinedToggleButton.setTextOn(Html
            .fromHtml("<u>" + getResources().getString(R.string.text_tool_dialog_underline_shortcut) + "</u>"));
    mUnderlinedToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean underlined = mUnderlinedToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setUnderlined(underlined);
            mUnderlined = underlined;
            hideKeyboard();
        }
    });

    mItalicToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_italic);
    mItalicToggleButton.setTextOn(Html
            .fromHtml("<i>" + getResources().getString(R.string.text_tool_dialog_italic_shortcut) + "</i>"));
    mItalicToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean italic = mItalicToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setItalic(italic);
            mItalic = italic;
            hideKeyboard();
        }
    });

    mBoldToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_bold);
    mBoldToggleButton.setTextOn(
            Html.fromHtml("<b>" + getResources().getString(R.string.text_tool_dialog_bold_shortcut) + "</b>"));
    mBoldToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean bold = mBoldToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setBold(bold);
            mBold = bold;
            hideKeyboard();
        }
    });

    mTextSizeSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_text_size);
    ArrayAdapter<CharSequence> textSizeAdapter = ArrayAdapter.createFromResource(mContext,
            R.array.text_tool_size_array, android.R.layout.simple_spinner_item);
    textSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mTextSizeSpinner.setAdapter(textSizeAdapter);

    mTextSizeSpinner.setBackgroundColor(Color.GRAY);
    mTextSizeSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            int size = Integer.parseInt(parent.getItemAtPosition(position).toString());
            mOnTextToolDialogChangedListener.setTextSize(size);
            mTextSizeIndex = position;
            if (mTextSizeSpinnerInitialized)
                hideKeyboard();
            else
                mTextSizeSpinnerInitialized = true;
        }

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

    builder.setView(view);
    builder.setNeutralButton(R.string.done, this);

    Dialog textDialog = builder.create();
    WindowManager.LayoutParams window_params = textDialog.getWindow().getAttributes();
    textDialog.getWindow().setDimAmount(0.0f);
    textDialog.getWindow().setAttributes(window_params);

    return textDialog;
}

From source file:es.glasspixel.wlanaudit.fragments.ScanFragment.java

@Override
public void onItemClick(final AdapterView<?> parent, View arg1, final int position, long arg3) {

    mCallback.onNetworkSelected((ScanResult) parent.getItemAtPosition(position));

}

From source file:com.ultramegasoft.flavordex2.util.EntryFormHelper.java

/**
 * Set up the autocomplete for the maker field.
 *//*  w w  w. j  av a2  s .  c om*/
private void setupMakersAutoComplete() {
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(mFragment.getContext(),
            R.layout.simple_dropdown_item_2line, null,
            new String[] { Tables.Makers.NAME, Tables.Makers.LOCATION },
            new int[] { android.R.id.text1, android.R.id.text2 }, 0);

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {
            final Uri uri;
            if (TextUtils.isEmpty(constraint)) {
                uri = Tables.Makers.CONTENT_URI;
            } else {
                uri = Uri.withAppendedPath(Tables.Makers.CONTENT_FILTER_URI_BASE,
                        Uri.encode(constraint.toString()));
            }

            final Bundle args = new Bundle();
            args.putParcelable("uri", uri);

            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mFragment.getLoaderManager().restartLoader(LOADER_MAKERS, args, EntryFormHelper.this);
                }
            });

            return adapter.getCursor();
        }
    });

    mTxtMaker.setAdapter(adapter);

    // fill in maker and origin fields with a suggestion
    mTxtMaker.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Cursor cursor = (Cursor) parent.getItemAtPosition(position);
            cursor.moveToPosition(position);

            final String name = cursor.getString(cursor.getColumnIndex(Tables.Makers.NAME));
            final String origin = cursor.getString(cursor.getColumnIndex(Tables.Makers.LOCATION));
            mTxtMaker.setText(name);
            mTxtOrigin.setText(origin);

            // skip origin field
            mTxtOrigin.focusSearch(View.FOCUS_DOWN).requestFocus();
        }
    });
}