List of usage examples for android.widget ArrayAdapter createFromResource
public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int textViewResId)
From source file:com.ultramegasoft.flavordex2.whiskey.WhiskeyEntryFormHelper.java
@Override protected void loadLayout(@NonNull View root) { super.loadLayout(root); mTxtType = root.findViewById(R.id.entry_type); final Context context = mFragment.getContext(); if (context != null) { mTxtType.setAdapter(ArrayAdapter.createFromResource(context, R.array.whiskey_types, android.R.layout.simple_dropdown_item_1line)); }/* w w w .ja v a 2 s . c o m*/ mTxtAge = root.findViewById(R.id.entry_stats_age); mTxtABV = root.findViewById(R.id.entry_stats_abv); }
From source file:org.ciasaboark.tacere.activity.fragment.BugReportDialogFragment.java
@Nullable @Override/*w w w . j a v a2 s .c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.activity_bug_report, container, false); final Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.report_types, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); Button closeButton = (Button) rootView.findViewById(R.id.bug_report_button_cancel); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BugReportDialogFragment.this.dismiss(); } }); final Button sendButton = (Button) rootView.findViewById(R.id.bug_report_button_send); sendButton.setEnabled(false); sendButton.setVisibility(View.INVISIBLE); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendButton.setEnabled(false); final ProgressBar busySpinner = (ProgressBar) rootView.findViewById(R.id.bug_report_progressbar); busySpinner.setVisibility(View.VISIBLE); EditText messageEditText = (EditText) rootView.findViewById(R.id.bug_report_message); final String messageText = messageEditText.getText().toString(); EditText emailEditText = (EditText) rootView.findViewById(R.id.bug_report_email); String emailText = emailEditText.getText().toString(); final String emailString = emailText.length() == 0 ? "no email address given" : emailText; final String spinnerSelection = spinner.getSelectedItem() == null ? "bug" : spinner.getSelectedItem().toString(); new Thread(new Runnable() { @Override public void run() { boolean reportSent = false; GitHubClient client = new GitHubClient(); client.setOAuth2Token(GitHubKeySet.GITHUB_OAUTH); RepositoryService repositoryService = new RepositoryService(client); try { Repository repository = repositoryService.getRepository("ciasaboark", "Tacere"); IssueService issueService = new IssueService(); issueService.getClient().setOAuth2Token(GitHubKeySet.GITHUB_OAUTH); Issue issue = new Issue(); issue.setTitle("Tacere issue submit"); String bodyText = ""; bodyText += messageText; bodyText += "\n\nEmail : " + emailString; bodyText += "\nAndroid Version: " + Build.VERSION.RELEASE; bodyText += "\nTacere version: " + Versioning.getVersionCode(); bodyText += "\nDevice: " + Build.MANUFACTURER + " - " + Build.MODEL; bodyText += "\nRom: " + Build.DISPLAY; issue.setBody(bodyText); Label label = new Label(); label.setName("autosubmit"); List<Label> labels = new ArrayList<Label>(); labels.add(label); String reportTypeLabel; switch (spinnerSelection.toLowerCase()) { case "bug": reportTypeLabel = "bug"; break; case "wishlist": reportTypeLabel = "wishlist"; break; default: Log.w(TAG, "unknown reportType " + spinnerSelection + ", assuming to " + "be a bug report"); reportTypeLabel = "bug"; } Label reportLabel = new Label(); reportLabel.setName(reportTypeLabel); labels.add(reportLabel); issue.setLabels(labels); UserService userService = new UserService(client); User user = userService.getUser("ciasaboark"); issue.setAssignee(user); try { issueService.createIssue(repository, issue); reportSent = true; } catch (IOException e) { Log.e(TAG, "unable to create issue in repository"); } } catch (IOException e) { Log.e(TAG, "unable to get list of user repositories"); } if (reportSent) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), R.string.bug_report_toast_sent, Toast.LENGTH_LONG) .show(); BugReportDialogFragment.this.dismiss(); } }); } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), R.string.bug_report_toast_failed, Toast.LENGTH_LONG).show(); busySpinner.setVisibility(View.INVISIBLE); sendButton.setEnabled(true); sendButton.setVisibility(View.VISIBLE); } }); } } }).start(); } }); EditText messageEditText = (EditText) rootView.findViewById(R.id.bug_report_message); messageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { //nothing to do here } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //nothing to do here } @Override public void afterTextChanged(Editable s) { if (s.length() > 0) { sendButton.setVisibility(View.VISIBLE); sendButton.setEnabled(true); } else { sendButton.setVisibility(View.INVISIBLE); sendButton.setEnabled(false); } } }); return rootView; }
From source file:net.tacks_a.ankicard.fragment.PointHistoryListFragment.java
private void setPointSummaryTypeToAdapter() { LogUtil.logDebug();/*from w ww . j a v a 2 s . com*/ // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_point_summary_type, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnPointSummaryType.setAdapter(adapter); if (0 < mSpnPointSummaryType.getCount()) { mSpnPointSummaryType.setSelection(0); } }
From source file:com.example.android.fragments._3_IncidentDescription.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ll = (RelativeLayout) inflater.inflate(R.layout.incidentdescription, container, false); sendbutton = ((Button) ll.findViewById(R.id.descr_finished_button)); sendbutton.setOnClickListener(this); locdescrp = ((TextView) ll.findViewById(R.id.detailed_location_description)); locdescrp.setOnClickListener(this); damagdescrinfo = ((TextView) ll.findViewById(R.id.damage_description_information)); damagdescrinfo.setOnClickListener(this); Spinner spinner = ((Spinner) ll.findViewById(R.id.facilities_spinner)); //spinner.setOnClickListener(this); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(ll.getContext(), R.array.facilities, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter);/*from w w w . ja va 2 s . c om*/ // Inflate the layout for this fragment return ll; }
From source file:com.e3h.usmcknowledge.activities.ranks.Officer.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_rank); sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view); sideNavigationView.setMenuItems(R.menu.side_navigation_menu); sideNavigationView.setMenuClickCallback(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mLocations = getResources().getStringArray(R.array.rankofficer); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.rankofficer, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); // Activate Navigation Mode Tabs mActionBar = getSupportActionBar();/*from ww w . j a v a 2 s . com*/ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(list, this); // Locate ViewPager in activity_main.xml mPager = (ViewPager) findViewById(R.id.pager); // Activate Fragment Manager FragmentManager fm = getSupportFragmentManager(); // Capture ViewPager page swipes ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); // Find the ViewPager Position mActionBar.setSelectedNavigationItem(position); } }; mPager.setOnPageChangeListener(ViewPagerListener); // Locate the adapter class called ViewPagerAdapter.java ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm); // Set the View Pager Adapter into ViewPager mPager.setAdapter(viewpageradapter); // Capture tab button clicks ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // Pass the position on tab click to ViewPager mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } }; String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" }; for (int i = 0; i < menuItems.length; i++) { String item = menuItems[i]; tab = mActionBar.newTab().setText(item).setTabListener(tabListener); mActionBar.addTab(tab); } }
From source file:com.e3h.usmcknowledge.activities.ranks.Warrant.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_rank); sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view); sideNavigationView.setMenuItems(R.menu.side_navigation_menu); sideNavigationView.setMenuClickCallback(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mLocations = getResources().getStringArray(R.array.rankwarrant); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.rankwarrant, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); // Activate Navigation Mode Tabs mActionBar = getSupportActionBar();/*from w w w . ja va2 s . c o m*/ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(list, this); // Locate ViewPager in activity_main.xml mPager = (ViewPager) findViewById(R.id.pager); // Activate Fragment Manager FragmentManager fm = getSupportFragmentManager(); // Capture ViewPager page swipes ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); // Find the ViewPager Position mActionBar.setSelectedNavigationItem(position); } }; mPager.setOnPageChangeListener(ViewPagerListener); // Locate the adapter class called ViewPagerAdapter.java ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm); // Set the View Pager Adapter into ViewPager mPager.setAdapter(viewpageradapter); // Capture tab button clicks ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // Pass the position on tab click to ViewPager mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } }; String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" }; for (int i = 0; i < menuItems.length; i++) { String item = menuItems[i]; tab = mActionBar.newTab().setText(item).setTabListener(tabListener); mActionBar.addTab(tab); } }
From source file:com.e3h.usmcknowledge.activities.RankActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_rank); sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view); sideNavigationView.setMenuItems(R.menu.side_navigation_menu); sideNavigationView.setMenuClickCallback(this); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mLocations = getResources().getStringArray(R.array.rankenlisted); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.rankenlisted, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); // Activate Navigation Mode Tabs mActionBar = getSupportActionBar();// w ww . j av a 2s.c o m mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); //getSupportActionBar().setListNavigationCallbacks(list, ); // Locate ViewPager in activity_main.xml mPager = (ViewPager) findViewById(R.id.pager); // Activate Fragment Manager FragmentManager fm = getSupportFragmentManager(); // Capture ViewPager page swipes ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); // Find the ViewPager Position mActionBar.setSelectedNavigationItem(position); } }; mPager.setOnPageChangeListener(ViewPagerListener); // Locate the adapter class called ViewPagerAdapter.java ViewPagerAdapterMainMenu viewpageradapter = new ViewPagerAdapterMainMenu(fm); // Set the View Pager Adapter into ViewPager mPager.setAdapter(viewpageradapter); // Capture tab button clicks ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { setmCounter(1); System.out.println("selected"); // Pass the position on tab click to ViewPager mPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub System.out.println("unselected"); setmCounter(0); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub System.out.println("reselected"); } }; String[] menuItems = { "USMC", "Navy", "Air Force", "Army", "Coast Guard" }; for (int i = 0; i < menuItems.length; i++) { String item = menuItems[i]; tab = mActionBar.newTab().setText(item).setTabListener(tabListener); mActionBar.addTab(tab); } }
From source file:com.actionbarsherlock.whmine.book.MenuActivity.java
/** Called when the activity is first created. */ @Override//from w w w. j a v a 2s. co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ActionBar ab = getSupportActionBar(); // set defaults for logs & home up ab.setDisplayHomeAsUpEnabled(showHomeUp); ab.setDisplayUseLogoEnabled(useLogo); String[] sections = getResources().getStringArray(R.array.sections); for (int i = 0; i < sections.length; i++) { ab.addTab(ab.newTab().setText(sections[i]).setTabListener(this)); } // set up list nav ab.setListNavigationCallbacks( ArrayAdapter.createFromResource(this, R.array.sections, R.layout.sherlock_spinner_dropdown_item), new OnNavigationListener() { public boolean onNavigationItemSelected(int itemPosition, long itemId) { // FIXME add proper implementation rotateLeftFrag(); return false; } }); // default to tab navigation showTabsNav(); // create a couple of simple fragments as placeholders final int MARGIN = 16; leftFrag = new RoundedColourFragment(getResources().getColor(R.color.android_green), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN); rightFrag = new RoundedColourFragment(getResources().getColor(R.color.honeycombish_blue), 2f, MARGIN / 2, MARGIN, MARGIN, MARGIN); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.root, leftFrag); ft.add(R.id.root, rightFrag); ft.commit(); }
From source file:com.actionbarsherlock.whmine.book.MainActivity.java
/** Called when the activity is first created. */ @Override/* w ww . j ava2 s . com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ActionBar ab = getSupportActionBar(); // set defaults for logs & home up ab.setDisplayHomeAsUpEnabled(showHomeUp); ab.setDisplayUseLogoEnabled(useLogo); String[] sections = getResources().getStringArray(R.array.sections); for (int i = 0; i < sections.length; i++) { ab.addTab(ab.newTab().setText(sections[i]).setTabListener(this)); } // set up list nav ab.setListNavigationCallbacks( ArrayAdapter.createFromResource(this, R.array.sections, R.layout.sherlock_spinner_dropdown_item), new OnNavigationListener() { public boolean onNavigationItemSelected(int itemPosition, long itemId) { // FIXME add proper implementation rotateLeftFrag(); return false; } }); showTabsNav(); // create a couple of simple fragments as placeholders final int MARGIN = 16; leftFrag = new RoundedColourFragment(getResources().getColor(R.color.android_green), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN); muneFrag = new RoundedColourFragment(getResources().getColor(R.color.honeycombish_blue), 2f, MARGIN / 2, MARGIN, MARGIN, MARGIN); rightFrag = new RoundedColourFragment(getResources().getColor(R.color.honeycombish_blue), 4f, MARGIN / 2, MARGIN, MARGIN, MARGIN); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.root, leftFrag); ft.add(R.id.root, muneFrag); ft.add(R.id.root, rightFrag); ft.commit(); }
From source file:ng.uavp.ch.ngusbterminal.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { thisview = inflater.inflate(R.layout.settings, container, false); SharedPreferences sharedPref = getActivity().getSharedPreferences("uart_settings", Context.MODE_PRIVATE); UartSettings defaults = new UartSettings(); Spinner spinner1 = (Spinner) thisview.findViewById(R.id.spinnerBaud); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(getActivity(), R.array.baud_array, R.layout.spinner_item_settings); // Specify the layout to use when the list of choices appears adapter1.setDropDownViewResource(R.layout.spinner_item_settings); // Apply the adapter to the spinner spinner1.setAdapter(adapter1);/*from w ww . j a v a2 s . c om*/ SetSpinnerSelection(sharedPref, spinner1, "baudrate", defaults.baudrate); Spinner spinner2 = (Spinner) thisview.findViewById(R.id.spinnerBits); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(getActivity(), R.array.databits_array, R.layout.spinner_item_settings); // Specify the layout to use when the list of choices appears adapter2.setDropDownViewResource(R.layout.spinner_item_settings); // Apply the adapter to the spinner spinner2.setAdapter(adapter2); SetSpinnerSelection(sharedPref, spinner2, "databits", defaults.dataBits); Spinner spinner3 = (Spinner) thisview.findViewById(R.id.spinnerParity); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(getActivity(), R.array.parity_array, R.layout.spinner_item_settings); // Specify the layout to use when the list of choices appears adapter3.setDropDownViewResource(R.layout.spinner_item_settings); // Apply the adapter to the spinner spinner3.setAdapter(adapter3); spinner3.setSelection(sharedPref.getInt("parity", defaults.parity)); Spinner spinner4 = (Spinner) thisview.findViewById(R.id.spinnerStopbits); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter4 = ArrayAdapter.createFromResource(getActivity(), R.array.stopbits_array, R.layout.spinner_item_settings); // Specify the layout to use when the list of choices appears adapter4.setDropDownViewResource(R.layout.spinner_item_settings); // Apply the adapter to the spinner spinner4.setAdapter(adapter4); SetSpinnerSelection(sharedPref, spinner4, "stopbits", defaults.stopBits); Spinner spinner5 = (Spinner) thisview.findViewById(R.id.spinnerFlow); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter5 = ArrayAdapter.createFromResource(getActivity(), R.array.flowcontrol, R.layout.spinner_item_settings); // Specify the layout to use when the list of choices appears adapter5.setDropDownViewResource(R.layout.spinner_item_settings); // Apply the adapter to the spinner spinner5.setAdapter(adapter5); spinner5.setSelection(sharedPref.getInt("flowcontrol", defaults.flowControl)); String[] devList; try { devList = usb.createDeviceList(); usbDevicesFound = devList.length; } catch (D2xxManager.D2xxException e) { devList = new String[1]; devList[0] = e.getLocalizedMessage(); } if (devList.length == 0) { devList = new String[1]; devList[0] = getString(R.string.error_noAdapter); } Spinner spinner6 = (Spinner) thisview.findViewById(R.id.spinnerInterfce); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(activity, R.layout.spinner_item_settings, devList); spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item_settings); spinner6.setAdapter(spinnerArrayAdapter); Button button1 = (Button) thisview.findViewById(R.id.button1); button1.setEnabled(usbDevicesFound > 0); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub doConnect(); } }); if (usbDevicesFound == 0) spinner6.setBackgroundColor(Color.MAGENTA); else spinner6.setBackgroundColor(Color.TRANSPARENT); return thisview; }