List of usage examples for android.widget ListAdapter getItem
Object getItem(int position);
From source file:com.zphinx.sortattributes.SortDialogManager.java
/** * Specifies the actions that ovccur when a stateTextView object is clicked * * @param activity// w ww . j ava 2s . c o m * The activity hosting this dialogManager * @param adapter * The list adapter containing multiple stateview * @param position * The position of the stateview object been clicked * @throws NotFoundException * If the specified state textview is not available */ private void clickStateTextView(final Activity activity, final ListAdapter adapter, int position) throws NotFoundException { if (position > -1) { int count = adapter.getCount(); for (int i = 0; i < count; i++) { if (i != position) { StateTextView anon = (StateTextView) adapter.getItem(i); if ((anon != null)) { anon.setCompoundDrawables(null, null, null, null); anon.setSortDirection(StateTextView.SORT_UNINITIALIZED); } } } StateTextView rowView = (StateTextView) adapter.getItem(position); Drawable[] draws = rowView.getCompoundDrawables(); if (draws == null) { draws = new Drawable[4]; } Log.d(TAG, "The stateView is: ........................." + rowView); Log.d(TAG, "The drawable is is: ........................." + draws[2]); setCurrentImage(rowView, draws, activity); selectedIndex = position; } }
From source file:com.ultramegasoft.flavordex2.dialog.FileSelectorDialog.java
/** * Called when an item is selected.//from ww w . ja va 2s . c o m * * @param index The item index */ private void selectItem(int index) { final ListAdapter adapter = mListView.getAdapter(); final int type = adapter.getItemViewType(index); final String item = (String) adapter.getItem(index); final File file = new File(mPath); if (type == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) { mPath = file.getParentFile().getPath(); } else { mPath = new File(file, item).getPath(); } if (type == FileListAdapter.FILE_TYPE) { selectCurrentFile(); } else { setupAdapter(); } }
From source file:tu.tracking.system.activities.TargetsListActivity.java
private TargetModel getTargetFromList(MotionEvent e) { ListAdapter listAdapter = listViewTargets.getAdapter(); float x = e.getX(); float y = e.getY(); float rx = e.getRawX(); float ry = e.getRawY(); int index = listViewTargets.pointToPosition(Math.round(x), Math.round(y)); if (index < 0 || index >= targets.size()) { return null; }/*from w w w . jav a 2 s. c o m*/ return (TargetModel) listAdapter.getItem(index); }
From source file:com.money.manager.ex.recurring.transactions.RecurringTransactionListFragment.java
private void showDatesWithEvents(CaldroidFragment caldroid) { ListAdapter adapter = getListAdapter(); int count = adapter.getCount(); ColorDrawable orange = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.holo_orange_dark)); RecurringTransaction tx = RecurringTransaction.createInstance(); for (int i = 0; i < count; i++) { Cursor cursor = (Cursor) adapter.getItem(i); tx.loadFromCursor(cursor);/*from w w w .j a v a2 s .c om*/ caldroid.setBackgroundDrawableForDate(orange, tx.getPaymentDate()); } }
From source file:com.example.android.expandingcells.ExpandingListView.java
@Override public void setAdapter(ListAdapter adapter) { //will require ListViewItems to be instances of ExpandableListItem if (adapter != null && !adapter.isEmpty() && !(adapter.getItem(0) instanceof ExpandableListItem)) { throw new IllegalArgumentException("ListItem must be ExpandablelistItem"); }//from w ww . j a va2 s . c o m super.setAdapter(adapter); }
From source file:org.lol.reddit.fragments.CommentListingFragment.java
public void handleCommentVisibilityToggle(RedditCommentView view) { final boolean isCollapsed = view.handleVisibilityToggle(); outerAdapter.notifyDataSetChanged(); if (isCollapsed) { final RedditPreparedComment comment = view.getComment(); final ListAdapter adapter = lv.getAdapter(); final int count = adapter.getCount(); for (int i = 0; i < count; i++) { if (adapter.getItem(i) == comment) { if (i == lv.getFirstVisiblePosition()) { lv.smoothScrollToPosition(i); }//from w ww . j ava 2s . co m break; } } } }
From source file:org.profeda.dictionary.SearchActivity.java
/** * Called when the activity is first created. *///from ww w .j av a 2s .co m @Override public void onCreate(Bundle savedInstanceState) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SearchActivity.this); if (pref.getBoolean("show_changelog", true) == true) { MessageBox.showChangeLog(this); } loadDictionaries(pref); if (pref.getBoolean("p_invert_colors", false) == true) { setTheme(R.style.Light); } else { setTheme(R.style.Dark); } super.onCreate(savedInstanceState); setContentView(R.layout.main); dict = new Dict(this, pref.getString("dictFile", null)); updateTitleBar(); readMRU(); final EditText searchbox = (EditText) findViewById(R.id.searchbox); final Button dictselectbutton = (Button) findViewById(R.id.dictselectbutton); final ListView listview = (ListView) findViewById(R.id.contentlist); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView l, View v, int position, long id) { ListAdapter la = ((ListView) l).getAdapter(); if (la instanceof GenericStringAdapter) { final String data = (String) la.getItem(position); if (data.startsWith("> ")) { searchbox.setText(data.substring(2)); doSearch(true); } } else if (la instanceof DictListAdapter) { final String[] data = (String[]) la.getItem(position); final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, null); String[] menu = new String[langs.size() + 1]; menu[0] = getString(R.string.copy_translation_to_clipboard); for (int i = 1; i < menu.length; i++) menu[i] = String.format(getString(R.string.search_translation_in_language), langs.get(i - 1).toLang); Matcher m = Pattern.compile("<b>(.*)<\\/b>.*").matcher(data[1]); if (!m.matches()) return; final String translation = m.group(1).trim(); new AlertDialog.Builder(SearchActivity.this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(translation).setItems(menu, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { switch (arg1) { case 0: ClipboardManager cm = (ClipboardManager) getSystemService( CLIPBOARD_SERVICE); cm.setText(translation); break; default: dict = langs.get(arg1 - 1); readMRU(); updateTitleBar(); searchbox.setText(translation); doSearch(true); } } }).show(); } } }); searchbox.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { doSearch(true); return true; } else { return false; } } }); final Drawable deleteIcon = getResources().getDrawable(R.drawable.textbox_clear); //deleteIcon.setBounds(0, 0, deleteIcon.getIntrinsicWidth(), deleteIcon.getIntrinsicHeight()); deleteIcon.setBounds(0, 0, 51, 30); // wtf??? die Zahlen sind empirisch ermittelt... ab right>=52 springt die hhe des editText searchbox.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { searchbox.setCompoundDrawables(null, null, s.toString().equals("") ? null : deleteIcon, null); //searchbox.setCompoundDrawablesWithIntrinsicBounds(null, null, s.toString().equals("") ? null : deleteIcon, null); searchbox.setCompoundDrawablePadding(0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (enableLivesearch && s.length() > 1 && dict.filePrefix != null && dictSearchInAction == false) { DictionarySearcher ds = new DictionarySearcher(); ds.targetList = (ListView) findViewById(R.id.contentlist); ds.execute(dict.filePrefix, s.toString()); } if (s.length() == 0) { displayMRU(); } } }); //searchbox.setCompoundDrawables(null, null, deleteIcon, null); searchbox.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (searchbox.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > searchbox.getWidth() - searchbox.getPaddingRight() - deleteIcon.getIntrinsicWidth()) { searchbox.setText(""); searchbox.setCompoundDrawables(null, null, null, null); } return false; } }); dictselectbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectDictionary(); } }); ((Button) findViewById(R.id.dictswapbutton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, dict.fromLang); if (langs.size() > 0) { dict = langs.get(0); readMRU(); updateTitleBar(); searchbox.setText(""); } else { MessageBox.alert(SearchActivity.this, getString(R.string.no_reverse_dict_found)); } } }); }
From source file:com.ubuntuone.android.files.activity.PreferencesActivity.java
private void openPreference(String key) { PreferenceScreen screen = getPreferenceScreen(); Log.d(TAG, "screen not null"); if (screen != null) { ListAdapter adapter = getPreferenceScreen().getRootAdapter(); for (int i = 0; i < adapter.getCount(); i++) { Preference p = (Preference) adapter.getItem(i); Log.d(TAG, "key is: " + p.getKey()); if (p.getKey().equals(key)) { screen.onItemClick(null, null, i, 0); break; }/* ww w . java2 s . com*/ } } }
From source file:net.osmand.plus.views.controls.DynamicListView.java
/** * Stores a reference to the views above and below the item currently * corresponding to the hover cell. It is important to note that if this * item is either at the top or bottom of the list, mAboveItemId or mBelowItemId * may be invalid.//from w w w . j a v a 2 s .co m */ private void updateNeighborViewsForID(long itemID) { ListAdapter adapter = getAdapter(); int position = getPositionForID(itemID); int pos = position; mAboveItemId = INVALID_ID; while (mAboveItemId == INVALID_ID && pos > 0) { pos--; mAboveItemId = adapter.getItemId(pos); if (mAboveItemId != INVALID_ID) { Object obj = adapter.getItem(pos); if (mActiveItemsList == null || !mActiveItemsList.contains(obj)) { mAboveItemId = INVALID_ID; } } } pos = position; mBelowItemId = INVALID_ID; while (mBelowItemId == INVALID_ID && pos < mItemsList.size()) { pos++; mBelowItemId = adapter.getItemId(pos); if (mBelowItemId != INVALID_ID) { Object obj = adapter.getItem(pos); if (mActiveItemsList == null || !mActiveItemsList.contains(obj)) { mBelowItemId = INVALID_ID; } } } }
From source file:at.alladin.rmbt.android.views.ResultQoSDetailView.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a 2 s. c o m public void taskEnded(JSONArray result) { System.out.println("ResultQoSDetail taskEnded"); this.testResult = result; if (resultFetchEndTaskListener != null) { resultFetchEndTaskListener.taskEnded(result); } ProgressBar resultProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar); TextView resultTextView = (TextView) view.findViewById(R.id.info_text); try { results = new QoSServerResultCollection(result); View successList = view.findViewById(R.id.qos_success_list); List<HashMap<String, String>> itemList = new ArrayList<HashMap<String, String>>(); int index = 0; for (QoSTestResultEnum type : QoSTestResultEnum.values()) { if (results.getQoSStatistics().getTestCounter(type) > 0) { HashMap<String, String> listItem = new HashMap<String, String>(); listItem.put("name", ConfigHelper.getCachedQoSNameByTestType(type, activity)); listItem.put("type_name", type.toString()); listItem.put("index", String.valueOf(index++)); itemList.add(listItem); } } ListAdapter valueList = new SimpleAdapter(activity, itemList, R.layout.qos_category_list_item, new String[] { "name" }, new int[] { R.id.name }); resultProgressBar.setVisibility(View.GONE); if (valueList.getCount() > 0) { //in case the view will change again: if (ListView.class.isAssignableFrom(successList.getClass())) { ((ListView) successList).setAdapter(valueList); ((ListView) successList).setOnItemClickListener(this); } else { ViewGroup vgList = (ViewGroup) successList; for (int i = 0; i < valueList.getCount(); i++) { View v = valueList.getView(i, null, null); QoSTestResultEnum key = QoSTestResultEnum .valueOf(((HashMap<String, String>) valueList.getItem(i)).get("type_name")); if (results.getQoSStatistics().getFailureCounter(key) > 0) { ImageView img = (ImageView) v.findViewById(R.id.status); img.setImageResource(R.drawable.traffic_lights_red); } TextView status = (TextView) v.findViewById(R.id.qos_type_status); status.setText((results.getQoSStatistics().getTestCounter(key) - results.getQoSStatistics().getFailedTestsCounter(key)) + "/" + results.getQoSStatistics().getTestCounter(key)); v.setOnClickListener(this); v.setTag(valueList.getItem(i)); vgList.addView(v); } } successList.invalidate(); resultTextView.setVisibility(View.GONE); successList.setVisibility(View.VISIBLE); } else { resultTextView.setText(R.string.result_qos_error_no_data_available); } } catch (Throwable t) { resultTextView.setText(R.string.result_qos_error_no_data_available); resultProgressBar.setVisibility(View.GONE); t.printStackTrace(); } }