List of usage examples for android.widget ArrayAdapter add
public void add(@Nullable T object)
From source file:com.example.google.walkway.MainActivity.java
private void setupNavList() { Log.d(LOG_TAG, "setupNavList()"); mNavListView = (ListView) this.findViewById(R.id.nav_list); ArrayAdapter<String> navAdapter = new NavArrayAdapter<String>(this, R.layout.listview_item); mNavListView.setAdapter(navAdapter); for (PlaceType placeType : NAV_PLACE_TYPES) { navAdapter.add(placeType.name().toLowerCase(Locale.US)); }/*from ww w.j a v a 2 s . c om*/ navAdapter.add("div"); // Divider navAdapter.add("about"); // TODO create constants final int aboutIndex = navAdapter.getCount() - 1; // TODO should have a better way mNavListView.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { if (index == aboutIndex) { mDrawerLayout.closeDrawer(mNavListView); Intent intent = new Intent(MainActivity.this, AboutActivity.class); startActivity(intent); } } }); View leftHandle = findViewById(R.id.left_handle); leftHandle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDrawerLayout.openDrawer(mNavListView); } }); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java
@SuppressWarnings("unchecked") private void refreshTestGroupsAndLog() { mLog = new StringBuilder(); Thread thread = new Thread() { @Override// www . j a va 2s .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.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java
private void update_agent_autocomplete(int id) { ArrayAdapter<String> agents = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line); Cursor c = mDbHelper.fetch_agents(); if (c.moveToFirst()) do {/*from w w w.jav a2 s . co m*/ agents.add(c.getString(c.getColumnIndex(DbAdapter.KEY_AGENT))); } while (c.moveToNext()); c.close(); AutoCompleteTextView agents_entry = (AutoCompleteTextView) findViewById(id); agents_entry.setThreshold(1); agents_entry.setAdapter(agents); }
From source file:edu.cmu.cylab.starslinger.view.FindContactActivity.java
public void generateView() { setContentView(R.layout.contact_adder); final ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); bar.setTitle(R.string.app_name);/*from w w w. jav a2s . c o m*/ bar.setSubtitle(R.string.title_find); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // Obtain handles to UI objects mEditTextName = (EditText) findViewById(R.id.contactNameEditText); mButtonDone = (Button) findViewById(R.id.contactDoneButton); mEditTextPassNext = (EditText) findViewById(R.id.EditTextPassphrase); mEditTextPassDone = (EditText) findViewById(R.id.EditTextPassphraseAgain); mTextViewLicensePrivacy = (TextView) findViewById(R.id.textViewLicensePrivacy); mSpinnerLanguage = (Spinner) findViewById(R.id.spinnerLanguage); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final ArrayList<String> codes = SafeSlinger.getApplication().getListLanguages(true); mSpinnerLanguage.setPrompt(getText(R.string.title_language)); mSpinnerLanguage.setAdapter(adapter); ArrayList<String> all = SafeSlinger.getApplication().getListLanguages(false); for (String l : all) { adapter.add(l); } mSpinnerLanguage.setSelection(codes.indexOf(SafeSlingerPrefs.getLanguage())); // read defaults and set them mSelectedName = SafeSlingerPrefs.getContactName(); // see if name is there... if (mSelectedName != null) { mEditTextName.setText(mSelectedName); } mEditTextPassNext.setVisibility(View.VISIBLE); mEditTextPassNext.setHint(R.string.label_PassHintCreate); mEditTextPassDone.setHint(R.string.label_PassHintRepeat); // enable hyperlinks mTextViewLicensePrivacy.setText(Html.fromHtml("<a href=\"" + SafeSlingerConfig.EULA_URL + "\">" + getText(R.string.menu_License) + "</a> / <a href=\"" + SafeSlingerConfig.PRIVACY_URL + "\">" + getText(R.string.menu_PrivacyPolicy) + "</a>")); mTextViewLicensePrivacy.setMovementMethod(LinkMovementMethod.getInstance()); mSpinnerLanguage.setOnItemSelectedListener(new OnItemSelectedListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long i) { if (!codes.get(position).equals(SafeSlingerPrefs.getLanguage())) { SafeSlingerPrefs.setLanguage(codes.get(position)); SafeSlinger.getApplication().updateLanguage(codes.get(position)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { recreate(); } else { generateView(); } } } @Override public void onNothingSelected(AdapterView<?> parent) { // We don't need to worry about nothing being selected } }); mEditTextName.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mSelectedName = mEditTextName.getText().toString(); } }); mButtonDone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onDoneButtonClicked(); } }); mEditTextPassDone.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { doValidatePassphrase(); return true; } return false; } }); }
From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java
private void update_station_autocomplete(int id) { ArrayAdapter<String> stations = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line); Cursor c = mDbHelper.fetch_stations(); if (c.moveToFirst()) do {//from w w w . j a v a 2s . co m stations.add(c.getString(c.getColumnIndex(DbAdapter.KEY_STN))); } while (c.moveToNext()); c.close(); AutoCompleteTextView stations_entry = (AutoCompleteTextView) findViewById(id); stations_entry.setThreshold(1); stations_entry.setAdapter(stations); }
From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java
private void update_operator_autocomplete(int id) { ArrayAdapter<String> operators = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line); Cursor c = mDbHelper.fetch_operators(); if (c.moveToFirst()) do {// w ww. j a v a 2 s .c o m operators.add(c.getString(c.getColumnIndex(DbAdapter.KEY_OPERATOR))); } while (c.moveToNext()); c.close(); AutoCompleteTextView operators_entry = (AutoCompleteTextView) findViewById(id); operators_entry.setThreshold(1); operators_entry.setAdapter(operators); }
From source file:com.gimranov.zandy.app.AttachmentActivity.java
/** * Refreshes the current list adapter/* w w w. jav a2 s .c o m*/ */ @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.xperia64.timidityae.PlaylistFragment.java
public void add() { if (mode) {/*w ww. ja va2 s . com*/ vola = parsePlist(tmpName = plistName); AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); loki = vola.size(); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(getResources().getString(R.string.plist_addto)); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getResources().getString(R.string.plist_addcs)); arrayAdapter.add(getResources().getString(R.string.plist_adds)); arrayAdapter.add(getResources().getString(R.string.plist_addf)); arrayAdapter.add(getResources().getString(R.string.plist_addft)); builderSingle.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { vola = parsePlist(plistName); switch (which) { case 0: setItem(((TimidityActivity) getActivity()).currSongName, 0); write(); break; case 1: new FileBrowserDialog().create(0, (((Globals.showVideos) ? Globals.musicVideoFiles : Globals.musicFiles)), PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; case 2: new FileBrowserDialog().create(1, null, PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; case 3: new FileBrowserDialog().create(2, null, PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; } } }); builderSingle.show(); } else { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(getResources().getString(R.string.plist_crea)); final EditText input = new EditText(getActivity()); alert.setView(input); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); File f = new File(playlistDir + value + ".tpl"); if (!f.exists()) { String[] needLol = null; try { new FileOutputStream(playlistDir + value + ".tpl").close(); } catch (FileNotFoundException e) { needLol = Globals.getDocFilePaths(getActivity(), playlistDir); } catch (IOException e) { e.printStackTrace(); } if (needLol != null) { Globals.tryToCreateFile(getActivity(), playlistDir + value + ".tpl"); } else { new File(playlistDir + value + ".tpl").delete(); try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } } getPlaylists(null); dialog.dismiss(); } }); alert.show(); } }
From source file:qauth.djd.qauthclient.main.ContentFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();/* ww w. j a v a 2 s. c om*/ if (args.getCharSequence(KEY_TITLE).toString().equals("Providers")) { View rootView = inflater.inflate(R.layout.providers_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); pAdapter = new ProviderAdapter(pDataset); mRecyclerView.setAdapter(pAdapter); final PackageManager pm = getActivity().getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { //Log.i(TAG, "Installed package :" + packageInfo.packageName); //Log.i(TAG, "Source dir : " + packageInfo.sourceDir); //Log.i(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); if (packageInfo.packageName.equals("qauth.djd.dummyclient")) { Provider provider = new Provider("DummyClient", packageInfo.packageName); pDataset.add(provider); pAdapter.notifyDataSetChanged(); } } //get local package names and cross reference with providers on server ("/provider/available") //display package names in listview //allow user to click on item to activate or deactivate // '-> have check box with progress bar indicating status return rootView; } else { View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); wAdapter = new WatchAdapter(wDataset); mRecyclerView.setAdapter(wAdapter); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.attachToRecyclerView(mRecyclerView); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("test", "clicked!"); AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle("Select Bluetooth Device"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice); new Thread(new Runnable() { public void run() { for (String s : getNodes()) { arrayAdapter.add(s); } } }).start(); builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String nodeId = arrayAdapter.getItem(which); String privKey = null; String pubKey = null; try { SecureRandom random = new SecureRandom(); RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4); KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC"); generator.initialize(spec, random); KeyPair pair = generator.generateKeyPair(); privKey = Base64.encodeToString(pair.getPrivate().getEncoded(), Base64.DEFAULT); pubKey = Base64.encodeToString(pair.getPublic().getEncoded(), Base64.DEFAULT); } catch (Exception e) { Log.i("generate", "error: " + e); } //Log.i("keys", "priv key : " + privKey); //String privKey = Base64.encodeToString(MainTabsActivity.privKey.getEncoded(), Base64.DEFAULT); //String pubKey = Base64.encodeToString(MainTabsActivity.pubKey.getEncoded(), Base64.DEFAULT); Keys keys = new Keys(privKey, pubKey); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); } catch (Exception e) { } try { out.writeObject(keys); } catch (Exception e) { } byte b[] = bos.toByteArray(); try { out.close(); } catch (Exception e) { } try { bos.close(); } catch (Exception e) { } Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, "REGISTER", b) .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "Failed to send message with status code: " + sendMessageResult.getStatus().getStatusCode()); } else if (sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "onResult successful!"); } } }); } }); builderSingle.show(); } }); mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this) .addOnConnectionFailedListener( new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.i("mGoogleApiClient", "onConnectionFailed: " + result); } }) // Request access only to the Wearable API .addApi(Wearable.API).build(); mGoogleApiClient.connect(); /*BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); for(BluetoothDevice bt : pairedDevices) Log.i("BluetoothDevice", "pairedDevice: " + bt.toString());*/ return rootView; } }
From source file:com.googlecode.CallerLookup.Main.java
public void doSave() { final Context context = this; final EditText input = new EditText(context); input.setHint(R.string.Name); AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle(R.string.SaveTitle);// w ww.ja va 2 s. c o m alert.setMessage(R.string.SaveMessage); alert.setView(input); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialog, int which) { final String name = SAVED_PREFIX + input.getText().toString().trim(); if (name.length() <= SAVED_PREFIX.length()) { AlertDialog.Builder error = new AlertDialog.Builder(context); error.setTitle(R.string.NameMissingTitle); error.setMessage(R.string.NameMissingMessage); error.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doSave(); } }); error.show(); return; } if (mLookupEntries.containsKey(name)) { AlertDialog.Builder confirm = new AlertDialog.Builder(context); confirm.setTitle(R.string.NameConfirmTitle); confirm.setMessage(R.string.NameConfirmMessage); confirm.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mLookupEntries.remove(name); mUserLookupEntries.remove(name); addUserLookupEntry(name); int count = mLookup.getCount(); for (int i = 1; i < count; i++) { if (mLookup.getItemAtPosition(i).toString().equals(name)) { mLookup.setSelection(i); break; } } } }); confirm.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { doSave(); } }); confirm.show(); return; } addUserLookupEntry(name); ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); adapter.add(name); mLookup.setSelection(mLookup.getCount() - 1); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert.show(); }