List of usage examples for android.widget ArrayAdapter getCount
@Override public int getCount()
From source file:com.hitachi_tstv.yodpanom.yaowaluk.tiresmanagement.CheckListActivity.java
public static String[] getStringArray(ArrayAdapter adapter) { String[] a = new String[adapter.getCount()]; for (int i = 0; i < a.length; i++) a[i] = adapter.getItem(i).toString(); return a;// ww w.j a v a 2s. co m }
From source file:com.poloure.simplerss.Utilities.java
static void setTitlesAndDrawerAndPage(Fragment fragment, int absolutePos) { String[] navTitles = s_resources.getStringArray(R.array.navigation_titles); if (null != fragment) { switchToFragment(fragment, false); }/*from www . ja v a2 s . co m*/ ListView list = s_fragmentDrawer.m_listView; HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) list.getAdapter(); int headers = headerAdapter.getHeadersCount(); int listPosition = -10 == absolutePos ? s_viewPager.getCurrentItem() + headers : absolutePos; int viewPagerPos = -10 == absolutePos ? s_viewPager.getCurrentItem() : absolutePos - headers; // Check the drawer item. String title = PagerAdapterTags.s_tagList.get(0); String subTitle = null; int imageRes = R.drawable.ic_action_labels; if (s_fragmentFavourites.isVisible()) { listPosition = 0; title = navTitles[0]; imageRes = R.drawable.ic_action_important; } else if (s_fragmentManage.isVisible()) { listPosition = 1; title = navTitles[1]; imageRes = R.drawable.ic_action_storage; } else if (s_fragmentSettings.isVisible()) { listPosition = 2; title = navTitles[2]; imageRes = R.drawable.ic_action_settings; } else { ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) headerAdapter.getWrappedAdapter(); if (null != adapter && 0 < adapter.getCount()) { String[] item = adapter.getItem(viewPagerPos); title = item[0]; int count = null == item[1] || item[1].isEmpty() ? 0 : Integer.parseInt(item[1]); String countString = s_resources.getQuantityString(R.plurals.actionbar_subtitle_unread, count, count); subTitle = 0 == count ? null : countString; } } s_actionBar.setTitle(title); s_actionBar.setSubtitle(subTitle); s_actionBar.setIcon(imageRes); list.setItemChecked(listPosition, true); // If we must change the view pager page. if (0 <= viewPagerPos) { // Switch the view pager page if different. if (s_viewPager.getCurrentItem() != viewPagerPos) { s_viewPager.setCurrentItem(viewPagerPos); } } }
From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java
private void createNewTopic(String value) { // make changes on page if (value.trim() != "") { Log.d(LOG_TAG, "Name: " + value); SingleTopicChoicePage fixedChoicePage = (SingleTopicChoicePage) mPage; Topic topic = new Topic(value); fixedChoicePage.addTopic(topic); ArrayAdapter<Object> adapter = (ArrayAdapter) getListAdapter(); adapter.insert(topic.getName(), adapter.getCount() - 1); // continue like normally mPage.getData().putSerializable(SingleTopicChoicePage.TOPIC, topic); mPage.notifyDataChanged();//from w ww .j a v a 2 s.co m } }
From source file:org.sufficientlysecure.keychain.ui.UploadKeyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.upload_key_activity); mUploadButton = findViewById(R.id.upload_key_action_upload); mKeyServerSpinner = (Spinner) findViewById(R.id.upload_key_keyserver); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Preferences.getPreferences(this).getKeyServers()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mKeyServerSpinner.setAdapter(adapter); if (adapter.getCount() > 0) { mKeyServerSpinner.setSelection(0); } else {/*from w ww . j av a 2s.co m*/ mUploadButton.setEnabled(false); } mUploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { uploadKey(); } }); mDataUri = getIntent().getData(); if (mDataUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); finish(); return; } }
From source file:org.thialfihar.android.apg.ui.UploadKeyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.upload_key_activity); mUploadButton = findViewById(R.id.upload_key_action_upload); mKeyserverSpinner = (Spinner) findViewById(R.id.upload_key_keyserver); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Preferences.getPreferences(this).getKeyservers()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mKeyserverSpinner.setAdapter(adapter); if (adapter.getCount() > 0) { mKeyserverSpinner.setSelection(0); } else {/*from ww w . j a v a2 s .co m*/ mUploadButton.setEnabled(false); } mUploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { uploadKey(); } }); mDataUri = getIntent().getData(); if (mDataUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!"); finish(); return; } }
From source file:net.tacks_a.ankicard.fragment.ExamCondFragment.java
private void setSortToAdapter() { LogUtil.logDebug();// w ww .ja v a 2 s . co m // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_sort_type, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnSortType.setAdapter(adapter); // ?? for (int i = 0; i < adapter.getCount(); i++) { if (mExamCond.getSortType() == i) { mSpnSortType.setSelection(i); } } }
From source file:net.tacks_a.ankicard.fragment.ExamCondFragment.java
private void setQuestionCountToAdapter() { LogUtil.logDebug();// ww w. jav a 2s . co m // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_question_count, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnQuestionCount.setAdapter(adapter); // ?? for (int i = 0; i < adapter.getCount(); i++) { String str1 = adapter.getItem(i).toString(); String str2 = Integer.toString(mExamCond.getQuestionCount()); if (str1.equals(str2)) { mSpnQuestionCount.setSelection(i); } } }
From source file:org.mythdroid.activities.Main.java
private void prepareWakeDialog(final Dialog dialog) { final ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, R.layout.simple_list_item_1, DatabaseUtil.getFrontendNames(ctx)); if (adapter.getCount() < 1) { ErrUtil.errDialog(ctx, dialog, R.string.noFes, WAKE_FRONTEND); return;//from w ww. j a va 2 s. c o m } ((AlertDialog) dialog).getListView().setAdapter(adapter); }
From source file:nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2.java
public void justifyListViewHeightBasedOnChildren(ListView listView) { ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter(); if (adapter == null) { return;//from w w w .j a v a 2 s. c o m } ViewGroup vg = listView; int totalHeight = 0; for (int i = 0; i < adapter.getCount(); i++) { View listItem = adapter.getView(i, null, vg); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams par = listView.getLayoutParams(); par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1)); listView.setLayoutParams(par); listView.requestLayout(); }
From source file:com.andrew.apollo.utils.MusicUtils.java
private static long[] getSongListForAdapter(final ArrayAdapter<Song> adapter) { if (adapter == null) { return sEmptyList; }/*ww w. ja v a2 s. c om*/ int count = adapter.getCount() - (adapter.getViewTypeCount() > 1 ? 1 : 0); List<Long> songList = new LinkedList<>(); for (int i = 0; i < count; i++) { try { long songId = adapter.getItem(i).mSongId; songList.add(songId); } catch (Throwable ignored) { // possible array out of bounds on adapter.getItem(i) } } if (songList.size() == 0) { return sEmptyList; } // until Java supports primitive types as generics, we'll live with this double copy. O(2n) Long[] list = new Long[songList.size()]; long[] result = ArrayUtils.toPrimitive(songList.toArray(list)); songList.clear(); return result; }