List of usage examples for android.widget ArrayAdapter add
public void add(@Nullable T object)
From source file:com.github.andrewlord1990.snackbarbuildersample.SampleActivity.java
private ListAdapter createAdapter() { final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); listView.setOnItemClickListener(new OnItemClickListener() { @Override//from w w w . j a v a2 s. c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String item = adapter.getItem(position); samples.get(item).onClick(view); } }); for (String sample : samples.keySet()) { adapter.add(sample); } return adapter; }
From source file:li.klass.fhem.fragments.TimerDetailFragment.java
private void createRepetitionSpinner(View view) { Spinner repetitionSpinner = getRepetitionSpinner(view); ArrayAdapter<String> repetitionAdapter = new ArrayAdapter<>(getActivity(), R.layout.spinnercontent); for (AtDevice.AtRepetition atRepetition : AtDevice.AtRepetition.values()) { repetitionAdapter.add(view.getContext().getString(atRepetition.getText())); }//from w w w . j a va 2s.c o m repetitionSpinner.setAdapter(repetitionAdapter); repetitionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { TimerDetailFragment.this.repetition = AtDevice.AtRepetition.values()[i]; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java
public void refreshMail() { JSONObject hashOptions = new JSONObject(); if (pageNum != 1) JsonParser.put(hashOptions, "page_number", pageNum); if (filterTag != "") JsonParser.put(hashOptions, "tags", filterTag); ClientSide.setContext(getActivity()); JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox"); if (result != null) { JSONArray messages = JsonParser.getJA(result, "messages"); List<Map<String, String>> mailList = new ArrayList<Map<String, String>>(); ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25. boolean hasMail = false; // By default, so that there's no way to screw up. if (messages.length() > 0) { for (int i = 0; i < messages.length(); i++) { JSONObject message = JsonParser.getJO(messages, i); Map<String, String> datum = new HashMap<String, String>(2); datum.put("from", JsonParser.getS(message, "from")); datum.put("subject", JsonParser.getS(message, "subject")); mailList.add(datum);/*from ww w. j a va 2 s. com*/ mailIds.add(JsonParser.getS(message, "id")); hasMail = true; } } else { Map<String, String> datum = new HashMap<String, String>(2); datum.put("from", "No new Mail available."); datum.put("subject", "Sorry. :("); mailList.add(datum); hasMail = false; } // Let the UI refresh when there's no mails. ListView mails = (ListView) getActivity().findViewById(R.id.mails); SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2, new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 }); mails.setAdapter(adapter); if (hasMail == true) { final Object[] MAIL_IDS = mailIds.toArray(); //spinnerReset = System.currentTimeMillis(); mails.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> a, View v, int pos, long id) { //if (System.currentTimeMillis() - spinnerReset < 1000) { //Nothing! //} //else if (System.currentTimeMillis() - spinnerReset > 1000) { String mailId = MAIL_IDS[pos].toString(); Intent intent = new Intent(getActivity(), com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class); intent.putExtra("mailId", mailId); getActivity().startActivity(intent); //} } }); // Populate the pages Spinner. ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage); double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25); for (int i = 1; i < pages; i++) { pagesSpinnerAdapter.add("" + i); } mailPages.setAdapter(pagesSpinnerAdapter); mailPages.recomputeViewAttributes(mailPages); mailPages.setSelection(pageNum - 1); } } }
From source file:com.example.am.myapplication.ContactAdder.java
/** * Called when the activity is first created. Responsible for initializing the UI. *//*ww w. j a v a2s .c om*/ @Override public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "Activity State: onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.contact_adder); // Obtain handles to UI objects mAccountSpinner = (Spinner) findViewById(R.id.accountSpinner); mContactNameEditText = (EditText) findViewById(R.id.contactNameEditText); mContactPhoneEditText = (EditText) findViewById(R.id.contactPhoneEditText); mContactEmailEditText = (EditText) findViewById(R.id.contactEmailEditText); mContactPhoneTypeSpinner = (Spinner) findViewById(R.id.contactPhoneTypeSpinner); mContactEmailTypeSpinner = (Spinner) findViewById(R.id.contactEmailTypeSpinner); mContactSaveButton = (Button) findViewById(R.id.contactSaveButton); // Prepare list of supported account types // Note: Other types are available in ContactsContract.CommonDataKinds // Also, be aware that type IDs differ between Phone and Email, and MUST be computed // separately. mContactPhoneTypes = new ArrayList<Integer>(); mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_HOME); mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_WORK); mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); mContactPhoneTypes.add(ContactsContract.CommonDataKinds.Phone.TYPE_OTHER); mContactEmailTypes = new ArrayList<Integer>(); mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_HOME); mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_WORK); mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_MOBILE); mContactEmailTypes.add(ContactsContract.CommonDataKinds.Email.TYPE_OTHER); // Prepare model for account spinner mAccounts = new ArrayList<AccountData>(); mAccountAdapter = new AccountAdapter(this, mAccounts); mAccountSpinner.setAdapter(mAccountAdapter); // Populate list of account types for phone ArrayAdapter<String> adapter; adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Iterator<Integer> iter; iter = mContactPhoneTypes.iterator(); while (iter.hasNext()) { adapter.add(ContactsContract.CommonDataKinds.Phone .getTypeLabel(this.getResources(), iter.next(), getString(R.string.undefinedTypeLabel)) .toString()); } mContactPhoneTypeSpinner.setAdapter(adapter); mContactPhoneTypeSpinner.setPrompt(getString(R.string.selectLabel)); // Populate list of account types for email adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); iter = mContactEmailTypes.iterator(); while (iter.hasNext()) { adapter.add(ContactsContract.CommonDataKinds.Email .getTypeLabel(this.getResources(), iter.next(), getString(R.string.undefinedTypeLabel)) .toString()); } mContactEmailTypeSpinner.setAdapter(adapter); mContactEmailTypeSpinner.setPrompt(getString(R.string.selectLabel)); // Prepare the system account manager. On registering the listener below, we also ask for // an initial callback to pre-populate the account list. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); // Register handlers for UI elements mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long i) { updateAccountSelection(); } public void onNothingSelected(AdapterView<?> parent) { // We don't need to worry about nothing being selected, since Spinners don't allow // this. } }); mContactSaveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onSaveButtonClicked(); } }); }
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { setHasOptionsMenu(true);//from w w w .j av a 2 s. co m fa = (ActionBarActivity) super.getActivity(); mActivity = getActivity(); view = inflater.inflate(R.layout.card_cpu_control, root, false); preferences = PreferenceManager.getDefaultSharedPreferences(mActivity); graph = (LineGraph) view.findViewById(R.id.graph); line = new Line(); LinePoint point = new LinePoint(); point.setX(currX); point.setY(1); line.addPoint(point); line.setColor(Color.parseColor("#FFBB33")); graph.addLine(line); graph.setLineToFill(0); availableFrequencies = new String[0]; String availableFrequenciesLine = CPUHelper.readOneLine(STEPS); if (availableFrequenciesLine != null) { availableFrequencies = availableFrequenciesLine.split(" "); Arrays.sort(availableFrequencies, new Comparator<String>() { @Override public int compare(String object1, String object2) { return Integer.valueOf(object1).compareTo(Integer.valueOf(object2)); } }); } int frequenciesNum = availableFrequencies.length - 1; String currentGovernor = CPUHelper.readOneLine(GOVERNOR); // String currentIo = CPUHelper.getIOScheduler(); String curMaxSpeed = CPUHelper.readOneLine(MAX_FREQ); String curMinSpeed = CPUHelper.readOneLine(MIN_FREQ); if (mIsTegra3) { String curTegraMaxSpeed = CPUHelper.readOneLine(TEGRA_MAX_FREQ); int curTegraMax = 0; try { curTegraMax = Integer.parseInt(curTegraMaxSpeed); if (curTegraMax > 0) { curMaxSpeed = Integer.toString(curTegraMax); } } catch (NumberFormatException ex) { curTegraMax = 0; } } String numOfCpus = CPUHelper.readOneLine(NUM_OF_CPUS); String[] cpuCount = numOfCpus.split("-"); if (cpuCount.length > 1) { try { int cpuStart = Integer.parseInt(cpuCount[0]); int cpuEnd = Integer.parseInt(cpuCount[1]); mNumOfCpu = cpuEnd - cpuStart + 1; if (mNumOfCpu < 0) mNumOfCpu = 1; } catch (NumberFormatException ex) { mNumOfCpu = 1; } } mCurFreq = (TextView) view.findViewById(R.id.currspeed); mMaxSlider = (SeekBar) view.findViewById(R.id.max_slider); mMaxSlider.setMax(frequenciesNum); mMaxSpeedText = (TextView) view.findViewById(R.id.max_speed_text); mMaxSpeedText.setText(toMHz(curMaxSpeed)); mMaxSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMaxSpeed)); mMaxSlider.setOnSeekBarChangeListener(this); mMinSlider = (SeekBar) view.findViewById(R.id.min_slider); mMinSlider.setMax(frequenciesNum); mMinSpeedText = (TextView) view.findViewById(R.id.min_speed_text); mMinSpeedText.setText(toMHz(curMinSpeed)); mMinSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMinSpeed)); mMinSlider.setOnSeekBarChangeListener(this); mGovernor = (Spinner) view.findViewById(R.id.governor); String[] availableGovernors = CPUHelper.readOneLine(GOVERNORS_LIST).split(" "); ArrayAdapter<CharSequence> governorAdapter = new ArrayAdapter<CharSequence>(mActivity, android.R.layout.simple_spinner_item); governorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (int i = 0; i < availableGovernors.length; i++) { governorAdapter.add(availableGovernors[i]); } mGovernor.setAdapter(governorAdapter); mGovernor.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor)); mGovernor.setOnItemSelectedListener(new GovListener()); // mIo = (Spinner) view.findViewById(R.id.io); // String[] availableIo = CPUHelper.getAvailableIOSchedulers(); // ArrayAdapter<CharSequence> ioAdapter = new ArrayAdapter<CharSequence>( // mActivity, android.R.layout.simple_spinner_item); // ioAdapter // .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // for (int i = 0; i < availableIo.length; i++) { // ioAdapter.add(availableIo[i]); // } // mIo.setAdapter(ioAdapter); // mIo.setSelection(Arrays.asList(availableIo).indexOf(currentIo)); // mIo.setOnItemSelectedListener(new IOListener()); return view; }
From source file:org.hedgewars.hedgeroid.Downloader.DownloadListFragment.java
public void run() { XmlPullParserFactory xmlPullFactory; try {/*www. j a v a 2 s. c om*/ xmlPullFactory = XmlPullParserFactory.newInstance(); XmlPullParser xmlPuller = xmlPullFactory.newPullParser(); URL url = new URL("http://www.xelification.com/tmp/downloads.xml"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()), 1024); xmlPuller.setInput(br); final ArrayAdapter<DownloadPackage> adapter = (ArrayAdapter<DownloadPackage>) getListAdapter(); int eventType = xmlPuller.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xmlPuller.getName().toLowerCase().equals("task")) { final DownloadPackage task = DownloadPackage.getTaskFromXML(getActivity(), xmlPuller); getActivity().runOnUiThread(new Runnable() { public void run() { adapter.add(task); } }); } } eventType = getEventType(xmlPuller); } } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.pdftron.pdf.controls.AddPageDialogFragment.java
private ArrayAdapter<CharSequence> getPageSizeSpinnerAdapter() { ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item); for (PageSize size : PageSize.values()) { switch (size) { case Letter: adapter.add(getString(R.string.dialog_add_page_page_size_letter)); break; case Legal: adapter.add(getString(R.string.dialog_add_page_page_size_legal)); break; case Ledger: adapter.add(getString(R.string.dialog_add_page_page_size_ledger)); break; case SameAsLast: if (!mCreateNewPdf) adapter.add(getString(R.string.dialog_add_page_page_size_same)); break; case A4:/*from w w w. j av a2 s . c o m*/ adapter.add(getString(R.string.dialog_add_page_page_size_a4)); break; case A3: adapter.add(getString(R.string.dialog_add_page_page_size_a3)); break; } } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); return adapter; }
From source file:com.mobicage.rogerthat.plugins.friends.RecommendServiceActivity.java
private void configureMailView() { T.UI();/*from w ww.j a v a 2 s . c o m*/ final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.recommend_email_text_field); emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>())); emailText.setThreshold(1); if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) { mService.postAtFrontOfBIZZHandler(new SafeRunnable() { @SuppressWarnings("unchecked") @Override protected void safeRun() throws Exception { L.d("RecommendServiceActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(RecommendServiceActivity.this); ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter(); for (int i = 0; i < emailList.size(); i++) { a.add(emailList.get(i)); } a.notifyDataSetChanged(); L.d("RecommendServiceActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { mFriendsPlugin.shareService(mServiceEmail, email); emailText.setText(null); UIUtils.hideKeyboard(RecommendServiceActivity.this, emailText); AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.service_recommendation_sent); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.recommend_email_button)).setOnClickListener(onClickListener); emailText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { onClickListener.onClick(view); return true; } return false; } }); }
From source file:com.pdftron.pdf.controls.AddPageDialogFragment.java
private ArrayAdapter<CharSequence> getOrientationSpinnerAdapter() { ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item); for (PageOrientation size : PageOrientation.values()) { switch (size) { case Portrait: adapter.add(getString(R.string.dialog_add_page_orientation_portrait)); break; case Landscape: adapter.add(getString(R.string.dialog_add_page_orientation_landscape)); break; }//from w w w . java 2s.c o m } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); return adapter; }
From source file:com.example.google.walkway.MainActivity.java
private void setupPlaceList() { Log.d(LOG_TAG, "setupPlaceList()"); mPlaceListView = (ListView) this.findViewById(R.id.place_list); ArrayAdapter<Place> placeAdapter = new PlaceArrayAdapter<Place>(this, R.layout.listview_item); mPlaceListView.setAdapter(placeAdapter); for (Place place : mPlaces) { placeAdapter.add(place); }/*from ww w . j a v a 2 s. com*/ mPlaceListView.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { // cannot use closeDrawer(mPlaceListView) since the list might not be a drawer. mDrawerLayout.closeDrawers(); if (index == mSelectedPlaceIndex) { showPlaceDetails(index); } else { setSelectedPlace(index); } } }); View rightHandle = findViewById(R.id.right_handle); if (rightHandle != null && rightHandle.getVisibility() == View.VISIBLE) { rightHandle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDrawerLayout.openDrawer(mPlaceListView); } }); } }