List of usage examples for android.widget ArrayAdapter clear
public void clear()
From source file:org.solovyev.android.calculator.history.AbstractCalculatorHistoryFragment.java
private void updateAdapter() { final List<CalculatorHistoryState> historyList = getHistoryList(); final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter(); try {//ww w . j a va 2s. co m adapter.setNotifyOnChange(false); adapter.clear(); for (CalculatorHistoryState historyState : historyList) { adapter.add(historyState); } } finally { adapter.setNotifyOnChange(true); } adapter.notifyDataSetChanged(); }
From source file:com.example.mapsv2.ClustersAreListsActivity.java
private void showInfo(final int x, int y, final Cluster cluster) { final int orientation = getResources().getConfiguration().orientation; // (re-)Load cluster data into the ListView @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = (ArrayAdapter<String>) listView.getAdapter(); adapter.clear(); for (Marker m : cluster.markers) { adapter.add(m.getTitle());// w w w . j av a 2 s.c o m } adapter.notifyDataSetChanged(); // Reconfigure the layout params to position the info window on screen FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) infoWindow.getLayoutParams(); if (orientation == Configuration.ORIENTATION_PORTRAIT) { lp.topMargin = y; lp.leftMargin = defaultMargin; lp.rightMargin = defaultMargin; lp.width = LayoutParams.MATCH_PARENT; lp.height = LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.LEFT | Gravity.TOP; infoWindow.setBackgroundResource(R.drawable.info_window_bg_up); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { lp.leftMargin = x + defaultMargin; lp.topMargin = defaultMargin; lp.bottomMargin = defaultMargin; lp.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL; lp.width = LayoutParams.WRAP_CONTENT; lp.height = LayoutParams.WRAP_CONTENT; infoWindow.setBackgroundResource(R.drawable.info_window_bg_left); } infoWindow.setLayoutParams(lp); fullScreenOverlay.setVisibility(View.VISIBLE); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java
@SuppressWarnings("unchecked") private void refreshTestGroupsAndLog() { mLog = new StringBuilder(); Thread thread = new Thread() { @Override//from ww w . ja v a 2 s .c o m public void run() { final boolean isNetBackend = IsNetBackend(); runOnUiThread(new Runnable() { @Override public void run() { ArrayAdapter<TestGroup> adapter = (ArrayAdapter<TestGroup>) mTestGroupSpinner.getAdapter(); adapter.clear(); adapter.add(new RoundTripTests()); adapter.add(new QueryTests()); adapter.add(new UpdateDeleteTests()); //adapter.add(new ClientSDKLoginTests()); adapter.add(new LoginTests(isNetBackend)); adapter.add(new MiscTests()); // adapter.add(new PushTests()); adapter.add(new CustomApiTests()); adapter.add(new SystemPropertiesTests(isNetBackend)); adapter.add(new EnhancedPushTests(isNetBackend)); adapter.add(new OfflineTests()); ArrayList<Pair<TestCase, String>> allTests = new ArrayList<Pair<TestCase, String>>(); ArrayList<Pair<TestCase, String>> allUnattendedTests = new ArrayList<Pair<TestCase, String>>(); for (int i = 0; i < adapter.getCount(); i++) { TestGroup group = adapter.getItem(i); allTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("Start of group: " + group.getName()), "Separator")); allUnattendedTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("Start of group: " + group.getName()), "Separator")); List<TestCase> testsForGroup = group.getTestCases(); for (TestCase test : testsForGroup) { allTests.add(new Pair<TestCase, String>(test, group.getName())); if (test.canRunUnattended()) { allUnattendedTests.add(new Pair<TestCase, String>(test, group.getName())); } } allTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("----" + group.getName() + "----"), "Separator")); allUnattendedTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("----" + group.getName() + "----"), "Separator")); } int unattendedTestsIndex = adapter.getCount(); adapter.add( new CompositeTestGroup(TestGroup.AllUnattendedTestsGroupName, allUnattendedTests)); adapter.add(new CompositeTestGroup(TestGroup.AllTestsGroupName, allTests)); if (shouldRunUnattended()) { mTestGroupSpinner.setSelection(unattendedTestsIndex); selectTestGroup(unattendedTestsIndex); changeCheckAllTests(true); runTests(); } else { mTestGroupSpinner.setSelection(0); selectTestGroup(0); } } }); } }; thread.start(); }
From source file:com.gimranov.zandy.app.AttachmentActivity.java
/** * Refreshes the current list adapter/*w w w. j a v a 2 s . c om*/ */ @SuppressWarnings("unchecked") private void refreshView() { ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter(); la.clear(); for (Attachment at : Attachment.forItem(item, db)) { la.add(at); } }
From source file:com.gimranov.zandy.app.AttachmentActivity.java
@Override protected Dialog onCreateDialog(int id) { final String attachmentKey = b.getString("attachmentKey"); final String itemKey = b.getString("itemKey"); final String content = b.getString("content"); final String mode = b.getString("mode"); AlertDialog dialog;/* w ww . j av a 2s .c om*/ switch (id) { case DIALOG_CONFIRM_NAVIGATE: dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.view_online_warning)) .setPositiveButton(getResources().getString(R.string.view), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // The behavior for invalid URIs might be nasty, but // we'll cross that bridge if we come to it. try { Uri uri = Uri.parse(content); startActivity(new Intent(Intent.ACTION_VIEW).setData(uri)); } catch (ActivityNotFoundException e) { // There can be exceptions here; not sure what would prompt us to have // URIs that the browser can't load, but it apparently happens. Toast.makeText(getApplicationContext(), getResources() .getString(R.string.attachment_intent_failed_for_uri, content), Toast.LENGTH_SHORT).show(); } } }) .setNeutralButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }) .create(); return dialog; case DIALOG_CONFIRM_DELETE: dialog = new AlertDialog.Builder(this) .setTitle(getResources().getString(R.string.attachment_delete_confirm)) .setPositiveButton(getResources().getString(R.string.menu_delete), new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") public void onClick(DialogInterface dialog, int whichButton) { Attachment a = Attachment.load(attachmentKey, db); a.delete(db); ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter(); la.clear(); for (Attachment at : Attachment.forItem(Item.load(itemKey, db), db)) { la.add(at); } } }) .setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }) .create(); return dialog; case DIALOG_NOTE: final EditText input = new EditText(this); input.setText(content, BufferType.EDITABLE); AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(getResources().getString(R.string.note)).setView(input).setPositiveButton( getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); String fixed = value.toString().replaceAll("\n\n", "\n<br>"); if (mode != null && mode.equals("new")) { Log.d(TAG, "Attachment created with parent key: " + itemKey); Attachment att = new Attachment(getBaseContext(), "note", itemKey); att.setNoteText(fixed); att.dirty = APIRequest.API_NEW; att.save(db); } else { Attachment att = Attachment.load(attachmentKey, db); att.setNoteText(fixed); att.dirty = APIRequest.API_DIRTY; att.save(db); } ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter(); la.clear(); for (Attachment a : Attachment.forItem(Item.load(itemKey, db), db)) { la.add(a); } la.notifyDataSetChanged(); } }) .setNeutralButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }); // We only want the delete option when this isn't a new note if (mode == null || !"new".equals(mode)) { builder = builder.setNegativeButton(getResources().getString(R.string.menu_delete), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Bundle b = new Bundle(); b.putString("attachmentKey", attachmentKey); b.putString("itemKey", itemKey); removeDialog(DIALOG_CONFIRM_DELETE); AttachmentActivity.this.b = b; showDialog(DIALOG_CONFIRM_DELETE); } }); } dialog = builder.create(); return dialog; case DIALOG_FILE_PROGRESS: mProgressDialog = new ProgressDialog(this); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog .setMessage(getResources().getString(R.string.attachment_downloading, b.getString("title"))); mProgressDialog.setIndeterminate(true); return mProgressDialog; default: Log.e(TAG, "Invalid dialog requested"); return null; } }
From source file:com.googlecode.CallerLookup.Main.java
@SuppressWarnings("unchecked") public void updateLookupEntries() { parseLookupEntries();//from w w w . j av a 2 s .c o m ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); if (adapter == null) { adapter = new ArrayAdapter<CharSequence>(getApplicationContext(), android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLookup.setAdapter(adapter); } else { adapter.clear(); } adapter.add("Custom"); for (String lookupEntryName : mLookupEntries.keySet()) { adapter.add(lookupEntryName); } for (String lookupEntryName : mUserLookupEntries.keySet()) { assert (!mLookupEntries.containsKey(lookupEntryName)); mLookupEntries.put(lookupEntryName, mUserLookupEntries.get(lookupEntryName)); adapter.add(lookupEntryName); } String name = mPrefs.getString(PREFS_LOOKUP, "Custom"); if ((name.length() > 0) && !name.equals("Custom")) { int count = mLookup.getCount(); for (int i = 1; i < count; i++) { if (mLookup.getItemAtPosition(i).toString().equals(name)) { mLookup.setSelection(i); break; } } } else { if (mLookup.getSelectedItemPosition() != 0) { mIgnoreItemSelection = true; mLookup.setSelection(0); } } }
From source file:org.uguess.android.sysinfo.NetStateManager.java
void refresh() { ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>(); data.add(dummyInfo);//from w ww. ja v a2 s .c om 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:org.strongswan.android.ui.VpnProfileDetailActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* the title is set when we load the profile, if any */ getSupportActionBar().setDisplayHomeAsUpEnabled(true); mDataSource = new VpnProfileDataSource(this); mDataSource.open();/*from ww w . j a v a2 s . c o m*/ setContentView(R.layout.profile_detail_view); mName = (MultiAutoCompleteTextView) findViewById(R.id.name); mNameWrap = (TextInputLayoutHelper) findViewById(R.id.name_wrap); mGateway = (EditText) findViewById(R.id.gateway); mGatewayWrap = (TextInputLayoutHelper) findViewById(R.id.gateway_wrap); mSelectVpnType = (Spinner) findViewById(R.id.vpn_type); mTncNotice = (RelativeLayout) findViewById(R.id.tnc_notice); mUsernamePassword = (ViewGroup) findViewById(R.id.username_password_group); mUsername = (EditText) findViewById(R.id.username); mUsernameWrap = (TextInputLayoutHelper) findViewById(R.id.username_wrap); mPassword = (EditText) findViewById(R.id.password); mUserCertificate = (ViewGroup) findViewById(R.id.user_certificate_group); mSelectUserCert = (RelativeLayout) findViewById(R.id.select_user_certificate); mSelectUserId = (Spinner) findViewById(R.id.select_user_id); mCheckAuto = (CheckBox) findViewById(R.id.ca_auto); mSelectCert = (RelativeLayout) findViewById(R.id.select_certificate); mShowAdvanced = (CheckBox) findViewById(R.id.show_advanced); mAdvancedSettings = (ViewGroup) findViewById(R.id.advanced_settings); mRemoteId = (MultiAutoCompleteTextView) findViewById(R.id.remote_id); mRemoteIdWrap = (TextInputLayoutHelper) findViewById(R.id.remote_id_wrap); mMTU = (EditText) findViewById(R.id.mtu); mMTUWrap = (TextInputLayoutHelper) findViewById(R.id.mtu_wrap); mPort = (EditText) findViewById(R.id.port); mPortWrap = (TextInputLayoutHelper) findViewById(R.id.port_wrap); mNATKeepalive = (EditText) findViewById(R.id.nat_keepalive); mNATKeepaliveWrap = (TextInputLayoutHelper) findViewById(R.id.nat_keepalive_wrap); mCertReq = (Switch) findViewById(R.id.cert_req); mIncludedSubnets = (EditText) findViewById(R.id.included_subnets); mIncludedSubnetsWrap = (TextInputLayoutHelper) findViewById(R.id.included_subnets_wrap); mExcludedSubnets = (EditText) findViewById(R.id.excluded_subnets); mExcludedSubnetsWrap = (TextInputLayoutHelper) findViewById(R.id.excluded_subnets_wrap); mBlockIPv4 = (CheckBox) findViewById(R.id.split_tunneling_v4); mBlockIPv6 = (CheckBox) findViewById(R.id.split_tunneling_v6); mSelectSelectedAppsHandling = (Spinner) findViewById(R.id.apps_handling); mSelectApps = (RelativeLayout) findViewById(R.id.select_applications); mIkeProposal = (EditText) findViewById(R.id.ike_proposal); mIkeProposalWrap = (TextInputLayoutHelper) findViewById(R.id.ike_proposal_wrap); mEspProposal = (EditText) findViewById(R.id.esp_proposal); mEspProposalWrap = (TextInputLayoutHelper) findViewById(R.id.esp_proposal_wrap); /* make the link clickable */ ((TextView) findViewById(R.id.proposal_intro)).setMovementMethod(LinkMovementMethod.getInstance()); final SpaceTokenizer spaceTokenizer = new SpaceTokenizer(); mName.setTokenizer(spaceTokenizer); mRemoteId.setTokenizer(spaceTokenizer); final ArrayAdapter<String> completeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line); mName.setAdapter(completeAdapter); mRemoteId.setAdapter(completeAdapter); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { findViewById(R.id.apps).setVisibility(View.GONE); mSelectSelectedAppsHandling.setVisibility(View.GONE); mSelectApps.setVisibility(View.GONE); } mGateway.addTextChangedListener(new TextWatcher() { @Override 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) { completeAdapter.clear(); completeAdapter.add(mGateway.getText().toString()); if (TextUtils.isEmpty(mGateway.getText())) { mNameWrap.setHelperText(getString(R.string.profile_name_hint)); mRemoteIdWrap.setHelperText(getString(R.string.profile_remote_id_hint)); } else { mNameWrap.setHelperText( String.format(getString(R.string.profile_name_hint_gateway), mGateway.getText())); mRemoteIdWrap.setHelperText( String.format(getString(R.string.profile_remote_id_hint_gateway), mGateway.getText())); } } }); mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mVpnType = VpnType.values()[position]; updateCredentialView(); } @Override public void onNothingSelected(AdapterView<?> parent) { /* should not happen */ mVpnType = VpnType.IKEV2_EAP; updateCredentialView(); } }); ((TextView) mTncNotice.findViewById(android.R.id.text1)).setText(R.string.tnc_notice_title); ((TextView) mTncNotice.findViewById(android.R.id.text2)).setText(R.string.tnc_notice_subtitle); mTncNotice.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new TncNoticeDialog().show(VpnProfileDetailActivity.this.getSupportFragmentManager(), "TncNotice"); } }); mSelectUserCert.setOnClickListener(new SelectUserCertOnClickListener()); mSelectUserIdAdapter = new CertificateIdentitiesAdapter(this); mSelectUserId.setAdapter(mSelectUserIdAdapter); mSelectUserId.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mUserCertEntry != null) { /* we don't store the subject DN as it is in the reverse order and the default anyway */ mSelectedUserId = position == 0 ? null : mSelectUserIdAdapter.getItem(position); } } @Override public void onNothingSelected(AdapterView<?> parent) { mSelectedUserId = null; } }); mCheckAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { updateCertificateSelector(); } }); mSelectCert.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(VpnProfileDetailActivity.this, TrustedCertificatesActivity.class); intent.setAction(TrustedCertificatesActivity.SELECT_CERTIFICATE); startActivityForResult(intent, SELECT_TRUSTED_CERTIFICATE); } }); mShowAdvanced.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { updateAdvancedSettings(); } }); mSelectSelectedAppsHandling.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mSelectedAppsHandling = SelectedAppsHandling.values()[position]; updateAppsSelector(); } @Override public void onNothingSelected(AdapterView<?> parent) { /* should not happen */ mSelectedAppsHandling = SelectedAppsHandling.SELECTED_APPS_DISABLE; updateAppsSelector(); } }); mSelectApps.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(VpnProfileDetailActivity.this, SelectedApplicationsActivity.class); intent.putExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps)); startActivityForResult(intent, SELECT_APPLICATIONS); } }); mId = savedInstanceState == null ? null : savedInstanceState.getLong(VpnProfileDataSource.KEY_ID); if (mId == null) { Bundle extras = getIntent().getExtras(); mId = extras == null ? null : extras.getLong(VpnProfileDataSource.KEY_ID); } loadProfileData(savedInstanceState); updateCredentialView(); updateCertificateSelector(); updateAdvancedSettings(); updateAppsSelector(); }
From source file:org.uguess.android.sysinfo.SiragonManager.java
void refresh() { ArrayAdapter<PrefItem> adapter = (ArrayAdapter<PrefItem>) getListAdapter(); adapter.setNotifyOnChange(false);/*from w w w. j a v a 2s.co m*/ adapter.clear(); for (Entry<String, PrefItem> ent : prefs.entrySet()) { adapter.add(ent.getValue()); } adapter.notifyDataSetChanged(); }