List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:com.github.wakhub.monodict.activity.settings.DownloadsActivity.java
@AfterViews void afterViews() { commonActivityTrait.initActivity(preferences); getActionBar().setDisplayHomeAsUpEnabled(true); sdCard = Environment.getExternalStorageDirectory(); resultIntent = getIntent();/* w ww.ja va 2 s. co m*/ dlTask = new DownloadTask(); listAdapter = new ArrayAdapter<DownloadsItem>(this, android.R.layout.simple_list_item_2, android.R.id.text1) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); DownloadsItem item = getItem(position); TextView text1 = (TextView) view.findViewById(android.R.id.text1); text1.setText(Dictionary.EMOJI + item.getName()); TextView text2 = (TextView) view.findViewById(android.R.id.text2); text2.setText(String.format("%s\nsize: %s", item.getDescription(), item.getSize())); return view; } }; setListAdapter(listAdapter); Downloads downloads = null; try { InputStream inputStream = getAssets().open("downloads.json"); downloads = (new Gson()).fromJson(IOUtils.toString(inputStream), Downloads.class); } catch (IOException e) { activityHelper.showError(e); return; } listAdapter.addAll(downloads.getItems()); }
From source file:de.baumann.hhsmoodle.activities.Activity_todo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); toDo_title = sharedPref.getString("toDo_title", ""); String toDo_text = sharedPref.getString("toDo_text", ""); toDo_icon = sharedPref.getString("toDo_icon", ""); toDo_create = sharedPref.getString("toDo_create", ""); todo_attachment = sharedPref.getString("toDo_attachment", ""); if (!sharedPref.getString("toDo_seqno", "").isEmpty()) { toDo_seqno = Integer.parseInt(sharedPref.getString("toDo_seqno", "")); }/*from w w w. j a v a 2 s. c om*/ setContentView(R.layout.activity_todo); setTitle(toDo_title); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); helper_main.onStart(Activity_todo.this); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } try { FileOutputStream fOut = new FileOutputStream(newFile()); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(toDo_text); myOutWriter.close(); fOut.flush(); fOut.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } lvItems = (ListView) findViewById(R.id.lvItems); items = new ArrayList<>(); readItems(); itemsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items); lvItems.setAdapter(itemsAdapter); lvItems.post(new Runnable() { public void run() { lvItems.setSelection(lvItems.getCount() - 1); } }); setupListViewListener(); final EditText etNewItem = (EditText) findViewById(R.id.etNewItem); ImageButton ib_paste = (ImageButton) findViewById(R.id.imageButtonPaste); final ImageButton ib_not = (ImageButton) findViewById(R.id.imageButtonNot); switch (todo_attachment) { case "true": ib_not.setImageResource(R.drawable.alert_circle); break; case "": ib_not.setImageResource(R.drawable.alert_circle_red); break; } ib_not.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (todo_attachment) { case "true": ib_not.setImageResource(R.drawable.alert_circle_red); sharedPref.edit().putString("toDo_attachment", "").apply(); todo_attachment = sharedPref.getString("toDo_attachment", ""); break; case "": ib_not.setImageResource(R.drawable.alert_circle); sharedPref.edit().putString("toDo_attachment", "true").apply(); todo_attachment = sharedPref.getString("toDo_attachment", ""); break; } } }); ib_paste.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) }; new android.app.AlertDialog.Builder(Activity_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.paste_date))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String dateNow = format.format(date); etNewItem.getText().insert(etNewItem.getSelectionStart(), dateNow); } if (options[item].equals(getString(R.string.paste_time))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timeNow = format.format(date); etNewItem.getText().insert(etNewItem.getSelectionStart(), timeNow); } } }).show(); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String itemText = etNewItem.getText().toString(); if (itemText.isEmpty()) { Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show(); } else { itemsAdapter.add(itemText); etNewItem.setText(""); writeItems(); lvItems.post(new Runnable() { public void run() { lvItems.setSelection(lvItems.getCount() - 1); } }); } } }); }
From source file:com.development.androrb.Orband.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w . j ava 2 s . c o m*/ //Intent getIntent = getIntent(); mediakind = getIntent().getStringExtra("mediakind"); sid = getIntent().getStringExtra("sid"); // globalstart=Integer.parseInt(getIntent().getStringExtra("start")); dummystr = getIntent().getStringExtra("start"); globalstart = Integer.parseInt(dummystr); dummystr = getIntent().getStringExtra("max"); globalcount = Integer.parseInt(dummystr); //Load Preferences //SharedPreferences preferences = getPreferences(MODE_WORLD_READABLE); //globalcount = Integer.parseInt(preferences.getString("MAX", "10")); splashtext = (TextView) findViewById(R.id.splashload); splashimage = (ImageView) findViewById(R.id.splashscreen); mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings); setListAdapter(mAdapter); ListView MyOrbList = getListView(); MyOrbList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { if (list.get(position).get("more") != "1") { String Mid = list.get(position).get("id"); String rurl = "http://api.orb.com/orb/xml/stream?sid=" + sid + "&mediumId=" + Mid + "&streamFormat=3gp&type=pda&width=480&height=360"; Intent mainIntent = new Intent(Orband.this, startplayer.class); mainIntent.putExtra("rurl", rurl); mainIntent.putExtra("sid", sid); mainIntent.putExtra("mid", Mid); mainIntent.putExtra("mediakind", mediakind); Orband.this.startActivity(mainIntent); } else { Intent mainIntent = new Intent(Orband.this, Orband.class); mainIntent.putExtra("mediakind", mediakind); mainIntent.putExtra("sid", sid); mainIntent.putExtra("start", "" + (globalstart + globalcount)); mainIntent.putExtra("max", "" + globalcount); Orband.this.startActivity(mainIntent); } } }); checkUpdate.start(); }
From source file:com.development.androrb.listfolders.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listfolders); splashimage = (ImageView) findViewById(R.id.splashscreen); splashtext = (TextView) findViewById(R.id.splashload); mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings); setListAdapter(mAdapter);/*from w ww.j a va2 s. c o m*/ ListView MyOrbList = getListView(); //Load Preferences SharedPreferences preferences = getPreferences(MODE_PRIVATE); Username = preferences.getString("UID", ""); Password = preferences.getString("PW", ""); //apikey = preferences.getString("API", ""); maxcount = preferences.getString("MAX", "-"); if (maxcount == "-") { SharedPreferences.Editor editor = preferences.edit(); editor.putString("MAX", "100"); editor.commit(); maxcount = "100"; } /* if (apikey.length() == 0) { showDialog(2); } */ if (Username.length() == 0) { showDialog(1); } if (Password.length() == 0) { showDialog(1); } if (maxcount.length() == 0) { showDialog(3); } splashimage.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (loggedin == 1) { splashimage.setVisibility(View.GONE); splashtext.setVisibility(View.GONE); } else { toasti(); Intent mainIntent = new Intent(listfolders.this, listfolders.class); listfolders.this.startActivity(mainIntent); listfolders.this.finish(); } } }); MyOrbList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { String rurl = ""; Intent mainIntent = new Intent(listfolders.this, Orband.class); if (position == 0) rurl = "video"; else if (position == 1) rurl = "audio.file"; else if (position == 2) rurl = "audio.web"; else if (position == 3) rurl = "photo"; else if (position == 4) rurl = "document"; mainIntent.putExtra("mediakind", rurl); mainIntent.putExtra("sid", sid); mainIntent.putExtra("start", "0"); mainIntent.putExtra("max", maxcount); listfolders.this.startActivity(mainIntent); } }); mAdapter.add("video files"); mAdapter.add("audio files"); mAdapter.add("web radios"); mAdapter.add("photos"); mAdapter.add("documents"); checkUpdate.start(); }
From source file:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountPreferences.java
/** * Initializes the preferences from the {@link PreferenceResonse} retrieved from the database. * @param res/*from w w w. j a v a 2 s . co m*/ */ public void initPreferences(PreferenceResponse res) { setContentView(R.layout.my_account_preferences); // Get default privacy value from user preferences privacyPreference = getApp().getSettings().getFacebookPrivacy(); if (privacyPreference == Visibility.FRIENDS) { selectedPrivacy = 0; facebookPrivacy = "Friends"; } if (privacyPreference == Visibility.FRIENDS_OF_FRIENDS) { selectedPrivacy = 1; facebookPrivacy = "Friends of friends"; } if (privacyPreference == Visibility.PUBLIC) { selectedPrivacy = 2; facebookPrivacy = "Public"; } listPreferences = (ListView) findViewById(R.id.listPreferences); btnFacebook = (Button) findViewById(R.id.preferencesFacebookButton); /**Preferences fetched from the strigs.xml*/ String[] preferences = getResources().getStringArray(R.array.preferences_array); prefAdap = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, preferences); listPreferences.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listPreferences.setAdapter(prefAdap); prefAdap.notifyDataSetChanged(); selectedItems = new ArrayList<String>(); checked = listPreferences.getCheckedItemPositions(); pref2 = res.getPreferences(); /**Fetch preferences from the database and display them*/ for (int i = 0; i < 5; i++) { switch (i) { case 0: if (pref2.getMusic()) { listPreferences.setItemChecked(i, true); } break; case 1: if (pref2.getAnimals()) { listPreferences.setItemChecked(i, true); } break; case 2: if (pref2.getBreaks()) { listPreferences.setItemChecked(i, true); } break; case 3: if (pref2.getTalking()) { listPreferences.setItemChecked(i, true); } break; case 4: if (pref2.getSmoking()) { listPreferences.setItemChecked(i, true); } break; } } prefAdap.notifyDataSetChanged(); listPreferences.addFooterView(btnFacebook); // Setting the Facebook privacy button btnFacebook.setText(Html.fromHtml("<b>" + "Set Facebook privacy" + "</b>" + "<br />" + "<small>" + facebookPrivacy + "</small>" + "<br />")); // Indicating that the preferences are initialized isPrefInitialized = true; }
From source file:cc.softwarefactory.lokki.android.fragments.ContactsFragment.java
private void setListAdapter() { ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.people_row_layout, peopleList) { ViewHolder holder;/*w ww . ja v a 2 s.c om*/ @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate(R.layout.people_row_layout, parent, false); holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.contact_name); holder.email = (TextView) convertView.findViewById(R.id.contact_email); holder.lastReport = (TextView) convertView.findViewById(R.id.last_report); holder.photo = (ImageView) convertView.findViewById(R.id.contact_photo); holder.checkICanSee = (CheckBox) convertView.findViewById(R.id.i_can_see); holder.checkCanSeeMe = (CheckBox) convertView.findViewById(R.id.can_see_me); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); //holder.imageLoader.cancel(); } String contactName = getItem(position); String email = mapping.get(contactName); AQuery aq = new AQuery(convertView); aq.id(holder.name).text(contactName); aq.id(holder.email).text(email); //aq.id(holder.photo).image(R.drawable.default_avatar); //aq.id(holder.photo).image(Utils.getDefaultAvatarInitials(contactName.substring(0, 1).toUpperCase() + contactName.substring(1, 2))); avatarLoader.load(email, holder.photo); aq.id(holder.lastReport).text(Utils.timestampText(timestamps.get(contactName))); aq.id(holder.checkCanSeeMe).checked(canSeeMe.contains(email)).tag(email); aq.id(holder.checkICanSee).tag(email); if (MainApplication.iDontWantToSee != null) { aq.id(holder.checkICanSee).checked(!MainApplication.iDontWantToSee.has(email)); aq.id(holder.photo) .clickable(!MainApplication.iDontWantToSee.has(email) && iCanSee.contains(email)); } else { aq.id(holder.photo).clickable(iCanSee.contains(email)); aq.id(holder.checkICanSee).checked(iCanSee.contains(email)).clickable(iCanSee.contains(email)); } holder.position = position; //holder.imageLoader = new LoadPhotoAsync(position, holder); //holder.imageLoader.execute(contactName); if (!iCanSee.contains(email)) { aq.id(holder.checkICanSee).invisible(); } else { aq.id(holder.checkICanSee).visible(); } return convertView; } }; aq.id(R.id.headers).visibility(View.VISIBLE); aq.id(R.id.contacts_list_view).adapter(adapter); }
From source file:com.citrus.sdk.fragments.Netbanking.java
private void initViews() { bankNames = new ArrayList<String>(); bankCodes = new ArrayList<String>(); for (int i = 0; i < netbankList.size(); i++) { String bankname = netbankList.get(i).getBankName(); String bankcid = netbankList.get(i).getBankcid(); bankNames.add(bankname);//from w w w. j av a 2s. c o m bankCodes.add(bankcid); } dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, bankNames); spinner = (Spinner) returnView.findViewById(R.id.bankOptions); spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { selectedBank = bankNames.get(arg2); selectedCode = bankCodes.get(arg2); } @Override public void onNothingSelected(AdapterView<?> arg0) { selectedBank = ""; } }); initSubmit(); }
From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.SearchMovie.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_movie); //Collect the intent object with parameters sent from the caller intent = getIntent();/*from w ww .j a v a2 s .c om*/ info = new TextView[5]; //In the info array of TextView type store id of each field info[0] = (TextView) findViewById(R.id.autoCompleteTextView); info[1] = (TextView) findViewById(R.id.editTitleSearch); info[2] = (TextView) findViewById(R.id.editGenreSearch); info[3] = (TextView) findViewById(R.id.editYearSearch); info[4] = (TextView) findViewById(R.id.editActorsSearch); //Ratings field is of type Spinner class with field values (PG, PG-13, R rated) dropdown = (Spinner) findViewById(R.id.spinnerSearch); adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dropdown.setAdapter(adapter); addButton = (Button) findViewById(R.id.addSearch); //Set the Video player ID, initially set the visibility to NONE playButton = (Button) findViewById(R.id.play); playButton.setVisibility(View.GONE); //There is no file available to play by default videoFile = null; context = getApplicationContext(); duration = Toast.LENGTH_SHORT; db = new MoviesDB(this); try { crsDB = db.openDB(); } catch (SQLException e) { e.printStackTrace(); } ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, gen); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch); textView.setAdapter(adapter); }
From source file:com.msopentech.applicationgateway.AgentsActivity.java
@Override public void onExecutionComplete(int operation, Object[] result) { try {//ww w . j ava2 s . c om mIsWorkInProgress = false; if (result == null) { AgentsActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Utility.showToastNotification(getResources().getString(R.string.agents_obtain_failed)); return; } }); } else { JSONArray rawAgentsStorage = (JSONArray) result[0]; ConnectionTraits traits = (ConnectionTraits) result[1]; for (int i = 0; i < rawAgentsStorage.length(); i++) { try { JSONObject item = rawAgentsStorage.getJSONObject(i); String agent_name = item.getString(Router.JSON_AGENT_DISPLAY_NAME_KEY); String agent_id = item.getString(Router.JSON_AGENT_ID_KEY); if (traits.agent.getAgentId().contentEquals(agent_id)) { agent_name = IN_USE_MARK + agent_name; } mAgentsDataStorage.add(new AgentEntity(agent_id, agent_name)); } catch (JSONException e) { continue; } } int agentsNumber = mAgentsDataStorage.size(); if (agentsNumber == 0) { Utility.showToastNotification("There are no agents available."); return; } String agentNames[] = new String[agentsNumber]; for (int i = 0; i < agentsNumber; i++) { agentNames[i] = mAgentsDataStorage.elementAt(i).getDisplayName(); } RelativeLayout agentsHeader = (RelativeLayout) getLayoutInflater().inflate(R.layout.list_header, null); ((TextView) agentsHeader.findViewById(R.id.list_header)).setText(R.string.agents_list_header); mAgentsListView.addHeaderView(agentsHeader, agentNames, false); ArrayAdapter<String> list1 = new ArrayAdapter<String>(AgentsActivity.this, android.R.layout.simple_list_item_1, agentNames); mAgentsListView.setAdapter(list1); showWorkInProgress(false); } showWorkInProgress(mIsWorkInProgress); } catch (final Exception e) { Utility.showAlertDialog( AgentsActivity.class.getSimpleName() + ".onPostExecute(): Failed. " + e.toString(), AgentsActivity.this); } }
From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java
public static <D extends FhemDevice<D>> void showSwitchOptionsMenu(final Context context, final D device, final TargetStateSelectedCallback callback) { AlertDialog.Builder contextMenu = new AlertDialog.Builder(context); contextMenu.setTitle(context.getResources().getString(R.string.switchDevice)); final List<String> setOptions = device.getSetList().getSortedKeys(); final String[] eventMapOptions = device.getAvailableTargetStatesEventMapTexts(); DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() { @Override//w w w . j a va2s .c o m public void onClick(DialogInterface dialog, int position) { final String option = setOptions.get(position); if (handleSelectedOption(context, device, option, callback)) return; dialog.dismiss(); } }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.list_item_with_arrow, eventMapOptions) { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(context, R.layout.list_item_with_arrow, null); } TextView textView = (TextView) convertView.findViewById(R.id.text); ImageView imageView = (ImageView) convertView.findViewById(R.id.image); textView.setText(getItem(position)); String setOption = setOptions.get(position); SetList setList = device.getSetList(); final SetListValue setListValue = setList.get(setOption); imageView.setVisibility(setListValue instanceof SetListGroupValue ? VISIBLE : GONE); return convertView; } }; contextMenu.setAdapter(adapter, clickListener); contextMenu.show(); }