List of usage examples for android.widget ArrayAdapter notifyDataSetChanged
@Override public void notifyDataSetChanged()
From source file:org.sufficientlysecure.keychain.ui.dialog.CreateKeyDialogFragment.java
private void setKeyLengthSpinnerValuesForAlgorithm(int algorithmId) { final ArrayAdapter<CharSequence> keySizeAdapter = (ArrayAdapter<CharSequence>) mKeySizeSpinner.getAdapter(); final Object selectedItem = mKeySizeSpinner.getSelectedItem(); keySizeAdapter.clear();/*from w w w. jav a 2 s. c o m*/ switch (algorithmId) { case Constants.choice.algorithm.rsa: replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa)); break; case Constants.choice.algorithm.elgamal: replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values); mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length break; case Constants.choice.algorithm.dsa: replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa)); break; } keySizeAdapter.notifyDataSetChanged(); // when switching algorithm, try to select same key length as before for (int i = 0; i < keySizeAdapter.getCount(); i++) { if (selectedItem.equals(keySizeAdapter.getItem(i))) { mKeySizeSpinner.setSelection(i); break; } } }
From source file:org.uguess.android.sysinfo.NetStateManager.java
void refresh() { ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>(); data.add(dummyInfo);// w w w. j a v a 2 s. c o m ArrayList<ConnectionItem> items = readStatesRaw(); if (items != null) { final int type = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_ORDER_TYPE, ORDER_TYPE_PROTO); final int direction = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_DIRECTION, ORDER_ASC); final Collator clt = Collator.getInstance(); switch (type) { case ORDER_TYPE_PROTO: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.proto, obj2.proto) * direction; } }); break; case ORDER_TYPE_LOCAL: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.local, obj2.local) * direction; } }); break; case ORDER_TYPE_REMOTE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.remoteName == null ? obj1.remote : obj1.remoteName, obj2.remoteName == null ? obj2.remote : obj2.remoteName) * direction; } }); break; case ORDER_TYPE_STATE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.state == null ? "" //$NON-NLS-1$ : obj1.state, obj2.state == null ? "" //$NON-NLS-1$ : obj2.state) * direction; } }); break; } data.addAll(items); } ArrayAdapter<ConnectionItem> adapter = (ArrayAdapter<ConnectionItem>) getListView().getAdapter(); adapter.setNotifyOnChange(false); adapter.clear(); for (int i = 0, size = data.size(); i < size; i++) { adapter.add(data.get(i)); } adapter.notifyDataSetChanged(); if (adapter.getCount() == 1) { Log.d(NetStateManager.class.getName(), "No network traffic detected"); //$NON-NLS-1$ } }
From source file:com.mobicage.rogerthat.AddFriendsActivity.java
private void configureMailView() { T.UI();//from www .j a va 2 s . c o m final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_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("AddFriendsActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.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("AddFriendsActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { if (mFriendsPlugin.inviteFriend(email, null, null, true)) { emailText.setText(null); UIUtils.hideKeyboard(AddFriendsActivity.this, emailText); } else { UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed)); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.add_via_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.rvl.android.getnzb.Search.java
public void buildItemList(int numhits) { String hits[][] = HITLIST;/*ww w.java 2s . com*/ setContentView(R.layout.links); String item = ""; Log.d(Tags.LOG, "* buildItemList()"); if (numhits == 0) { Toast.makeText(this, "No search result found!", Toast.LENGTH_LONG); return; } // -- Bind the itemlist to the itemarray with the arrayadapter ArrayList<String> items = new ArrayList<String>(); ArrayAdapter<String> aa = new SearchResultRowAdapter(this, items); //ArrayAdapter<String> aa = new ArrayAdapter<String>(this,com.rvl.android.getnzb.R.layout.itemslist,items); ListView itemlist = (ListView) findViewById(R.id.itemlist01); itemlist.setCacheColorHint(00000000); itemlist.setAdapter(aa); registerForContextMenu(itemlist); itemlist.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int position, long id) { String pos = Integer.toString(position); Log.d(Tags.LOG, "Sending download command for position " + pos); new downloadfile().execute(pos); } }); // -- Log.d(Tags.LOG, "Building hitlist..."); for (int i = 0; i < hits.length; i++) { item += hits[i][0] + "#" + hits[i][1] + "#" + hits[i][2] + "#" + hits[i][4]; items.add(item); Log.d(Tags.LOG, "item:" + item); item = ""; } aa.notifyDataSetChanged(); // Enable or disable the button for next results page... Button nextbutton = (Button) findViewById(R.id.btn_next); nextbutton.setEnabled(ENABLE_NEXTBUTTON); }
From source file:com.Candy.sizer.CandySizer.java
private void showDialog(int id, final String item, final ArrayAdapter<String> adapter, int itemCounter) { // startup dialog final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); if (id == STARTUP_DIALOG) { // create warning dialog alert.setMessage(R.string.sizer_message_startup).setTitle(R.string.caution).setCancelable(true) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok dialog.cancel(); }//from w w w. j ava 2s . c o m }); // delete dialog } else if (id == DELETE_DIALOG) { alert.setMessage(R.string.sizer_message_delete) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok // call delete new CandySizer.SlimDeleter().execute(item); // remove list entry adapter.remove(item); adapter.notifyDataSetChanged(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } else if (id == DELETE_MULTIPLE_DIALOG) { String message; if (itemCounter == 1) { message = getResources().getString(R.string.sizer_message_delete_multi_one); } else { message = getResources().getString(R.string.sizer_message_delete_multi); } alert.setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { final ListView lv = (ListView) getView().findViewById(R.string.listsystem); ArrayList<String> itemsList = new ArrayList<String>(); SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = lv.getCount() - 1; i > 0; i--) { if (checked.get(i)) { String appName = mSysApp.get(i); itemsList.add(appName); // remove list entry lv.setItemChecked(i, false); adapter.remove(appName); } } adapter.notifyDataSetChanged(); new CandySizer.SlimDeleter().execute(itemsList.toArray(new String[itemsList.size()])); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } else if (id == REBOOT_DIALOG) { // create warning dialog alert.setMessage(R.string.reboot).setTitle(R.string.caution).setCancelable(true) .setPositiveButton(R.string.reboot_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok try { dos.writeBytes("reboot"); dos.flush(); dos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).setNegativeButton(R.string.reboot_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } // show warning dialog alert.show(); }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
private void setDrawerChoices() { m_drawerList.clearChoices();/*from w w w .j ava2 s.co m*/ boolean haveContexts = false; boolean haveProjects = false; for (int i = 0; i < m_lists.size(); i++) { char sigil = m_lists.get(i).charAt(0); String item = m_lists.get(i).substring(1); if (sigil == '@' && m_app.m_contexts.contains(item)) { m_drawerList.setItemChecked(i, true); haveContexts = true; } else if (sigil == '+' && m_app.m_projects.contains(item)) { m_drawerList.setItemChecked(i, true); haveProjects = true; } } if (haveContexts) { if (!m_app.m_filters.contains(getString(R.string.filter_tab_contexts))) { m_app.m_filters.add(getString(R.string.filter_tab_contexts)); } } else { m_app.m_filters.remove(getString(R.string.filter_tab_contexts)); m_app.m_contexts = new ArrayList<String>(); } if (haveProjects) { if (!m_app.m_filters.contains(getString(R.string.filter_tab_projects))) { m_app.m_filters.add(getString(R.string.filter_tab_projects)); } } else { m_app.m_filters.remove(getString(R.string.filter_tab_projects)); m_app.m_projects = new ArrayList<String>(); } ArrayAdapter<?> adapter = (ArrayAdapter<?>) m_drawerList.getAdapter(); if (adapter != null) { adapter.notifyDataSetChanged(); } }
From source file:org.notfunnynerd.opencoinmap.MapActivity.java
private void showRadiusDialog() { final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle(R.string.near_you); LayoutInflater inflater = getLayoutInflater(); final View layout = inflater.inflate(R.layout.radius_dialog, null); dialogBuilder.setView(layout);/*from w w w . j a v a 2s . c o m*/ final AlertDialog dialog = dialogBuilder.create(); dialog.show(); final TextView radiusValue = (TextView) layout.findViewById(R.id.radiusValue); ListView listView = (ListView) layout.findViewById(R.id.listPlaces); final ArrayList<Place> localPlaces = new ArrayList<Place>(); final ArrayAdapter<Place> adapter = new ArrayAdapter<Place>(this, android.R.layout.simple_list_item_1, localPlaces); listView.setAdapter(adapter); final SeekBar seekRadius = (SeekBar) layout.findViewById(R.id.seekRadius); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { dialog.dismiss(); Marker marker = getMarkerFromPlace(localPlaces.get(position)); mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition())); marker.showInfoWindow(); } }); seekRadius.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int current = 0; @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { current = progress; radiusValue.setText("" + progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { localPlaces.clear(); for (Place place : getPlacesWithinRadius(current)) { localPlaces.add(place); } adapter.notifyDataSetChanged(); } }); ((Button) layout.findViewById(R.id.okButton)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
From source file:org.numixproject.hermes.activity.ConversationActivity.java
private void updateAutoComplete() { ArrayAdapter<String> autoCompleteAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_item, binder.getService().getConnection(server.getId()) .getUsersAsStringArray(pagerAdapter.getItem(pager.getCurrentItem()).getName())); autoCompleteAdapter.notifyDataSetChanged(); input.setAdapter(autoCompleteAdapter); }
From source file:com.coderdojo.libretalk.MainActivity.java
private final void printMsg(final LibretalkMessageData message) { ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this, android.R.layout.simple_list_item_1, mMessageListArray); ListView listView = (ListView) findViewById(R.id.message_list); listView.setAdapter(adapter);/* w ww . jav a 2 s .com*/ listView.setStackFromBottom(true); final String sourceMessage = message.getSenderTag() + ": " + message.getData(); final SpannableString formattedText = new SpannableString(sourceMessage); if (message.getData().startsWith(">")) { formattedText.setSpan( new ForegroundColorSpan(LibretalkMessageData.getColorFromString(message.getSenderTag())), sourceMessage.indexOf(message.getSenderTag()), sourceMessage.indexOf(message.getSenderTag()) + message.getSenderTag().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); formattedText.setSpan(new ForegroundColorSpan(Color.rgb(120, 153, 34)), sourceMessage.indexOf(message.getData()), sourceMessage.indexOf(message.getData()) + message.getData().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { formattedText.setSpan( new ForegroundColorSpan(LibretalkMessageData.getColorFromString(message.getSenderTag())), sourceMessage.indexOf(message.getSenderTag()), sourceMessage.indexOf(message.getSenderTag()) + message.getSenderTag().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mMessageListArray.add(formattedText); adapter.notifyDataSetChanged(); }
From source file:com.Candy.sizer.CandySizer.java
private void selectDialog(final ArrayList<String> sysAppProfile, final ArrayAdapter<String> adapter) { AlertDialog.Builder select = new AlertDialog.Builder(getActivity()); select.setItems(R.array.slimsizer_profile_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' argument contains the index position // of the selected item short state = sdAvailable(); File path = new File(Environment.getExternalStorageDirectory() + "/Slim"); File savefile = new File(path + "/slimsizer.stf"); if (which == 0) { // load profile action if (state >= 1) { String profile; try { // read savefile and create arraylist profile = new Scanner(savefile, "UTF-8").useDelimiter("\\A").next(); ArrayList<String> profileState = new ArrayList<String>( Arrays.asList(profile.split(", "))); // create arraylist of unique entries in // sysAppProfile (currently installed apps) ArrayList<String> deleteList = new ArrayList<String>(); for (String item : sysAppProfile) { if (!profileState.contains(item)) { deleteList.add(item); }//from w w w .j a v a 2s .c o m } // delete all entries in deleteList ArrayList<String> itemsList = new ArrayList<String>(); for (int i = deleteList.size() - 1; i > 0; i--) { String item = deleteList.get(i); itemsList.add(item); // remove list entry adapter.remove(item); } adapter.notifyDataSetChanged(); new CandySizer.SlimDeleter().execute(itemsList.toArray(new String[itemsList.size()])); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnoread)); } } else if (which == 1) { // save profile action if (state == 2) { try { // create directory if it doesnt exist if (!path.exists()) { path.mkdirs(); } // create string from arraylists String lists = sysAppProfile.toString(); lists = lists.replace("][", ","); lists = lists.replace("[", ""); lists = lists.replace("]", ""); // delete savefile if it exists (overwrite) if (savefile.exists()) { savefile.delete(); } // create savefile and output lists to it FileWriter outstream = new FileWriter(savefile); BufferedWriter save = new BufferedWriter(outstream); save.write(lists); save.close(); // check for success if (savefile.exists()) { toast(getResources().getString(R.string.sizer_message_filesuccess)); } else { toast(getResources().getString(R.string.sizer_message_filefail)); } } catch (IOException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnowrite)); } } } }); select.show(); }