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:net.tacks_a.ankicard.fragment.ExamCondFragment.java
private void setQuestionCountToAdapter() { LogUtil.logDebug();/*from w w w .jav a 2 s . co m*/ // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_question_count, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnQuestionCount.setAdapter(adapter); // ?? for (int i = 0; i < adapter.getCount(); i++) { String str1 = adapter.getItem(i).toString(); String str2 = Integer.toString(mExamCond.getQuestionCount()); if (str1.equals(str2)) { mSpnQuestionCount.setSelection(i); } } }
From source file:org.libreoffice.ui.LibreOfficeUIActivity.java
public void createUI() { setContentView(R.layout.activity_document_browser); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// ww w .j a va2 s .c om ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(false); //This should show current directory if anything actionBar.setDisplayHomeAsUpEnabled(true); //make the navigation spinner Context context = actionBar.getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.file_view_modes, android.R.layout.simple_spinner_item); list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(list, this); LinearLayout content = (LinearLayout) findViewById(R.id.browser_main_content); if (viewMode == GRID_VIEW) { // code to make a grid view getLayoutInflater().inflate(R.layout.file_grid, content); gv = (GridView) findViewById(R.id.file_explorer_grid_view); gv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { open(position); } }); actionBar.setSelectedNavigationItem(filterMode + 1);//This triggers the listener which modifies the view. registerForContextMenu(gv); } else { getLayoutInflater().inflate(R.layout.file_list, content); lv = (ListView) findViewById(R.id.file_explorer_list_view); lv.setClickable(true); actionBar.setSelectedNavigationItem(filterMode + 1); registerForContextMenu(lv); } // setup the drawer drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.left_drawer); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.document_locations, R.string.close_document_locations) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); supportInvalidateOptionsMenu(); drawerList.requestFocus(); // Make keypad navigation easier } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); supportInvalidateOptionsMenu(); } }; drawerToggle.setDrawerIndicatorEnabled(true); drawerLayout.setDrawerListener(drawerToggle); drawerToggle.syncState(); // Set the adapter for the list view drawerList.setAdapter( new ArrayAdapter<String>(this, R.layout.item_in_drawer, documentProviderFactory.getNames())); // Set the list's click listener drawerList.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switchToDocumentProvider(documentProviderFactory.getProvider(position)); } }); }
From source file:org.chromium.latency.walt.ScreenResponseFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { timesToBlink = getIntPreference(getContext(), R.string.preference_screen_blinks, 20); shouldShowLatencyChart = getBooleanPreference(getContext(), R.string.preference_show_blink_histogram, true); enableFullScreen = getBooleanPreference(getContext(), R.string.preference_screen_fullscreen, true); if (getBooleanPreference(getContext(), R.string.preference_systrace, true)) { traceLogger = TraceLogger.getInstance(); }/*from ww w. j ava 2s . c o m*/ waltDevice = WaltDevice.getInstance(getContext()); logger = SimpleLogger.getInstance(getContext()); // Inflate the layout for this fragment final View view = inflater.inflate(R.layout.fragment_screen_response, container, false); stopButton = view.findViewById(R.id.button_stop_screen_response); startButton = view.findViewById(R.id.button_start_screen_response); blackBox = (TextView) view.findViewById(R.id.txt_black_box_screen); fastSurfaceView = (FastPathSurfaceView) view.findViewById(R.id.fast_path_surface); spinner = (Spinner) view.findViewById(R.id.spinner_screen_response); buttonBarView = view.findViewById(R.id.button_bar); ArrayAdapter<CharSequence> modeAdapter = ArrayAdapter.createFromResource(getContext(), R.array.screen_response_mode_array, android.R.layout.simple_spinner_item); modeAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); spinner.setAdapter(modeAdapter); stopButton.setEnabled(false); blackBox.setMovementMethod(new ScrollingMovementMethod()); brightnessChartLayout = view.findViewById(R.id.brightness_chart_layout); view.findViewById(R.id.button_close_chart).setOnClickListener(this); brightnessChart = (LineChart) view.findViewById(R.id.chart); latencyChart = (HistogramChart) view.findViewById(R.id.latency_chart); if (getBooleanPreference(getContext(), R.string.preference_auto_increase_brightness, true)) { increaseScreenBrightness(); } return view; }
From source file:fabiogentile.powertutor.ui.UMLogger.java
/** * Called when the activity is first created. *//*from ww w . ja va 2 s . co m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate: "); prefs = PreferenceManager.getDefaultSharedPreferences(this); serviceIntent = new Intent(this, UMLoggerService.class); conn = new CounterServiceConnection(); SystemInfo.getInstance().setContext(getApplicationContext()); setContentView(R.layout.main); ArrayAdapter<?> adapterxaxis = ArrayAdapter.createFromResource(this, R.array.xaxis, android.R.layout.simple_spinner_item); adapterxaxis.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //If Marshmallow ask permission explicitly if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) askPermission(); serviceStartButton = (Button) findViewById(R.id.servicestartbutton); appViewerButton = (Button) findViewById(R.id.appviewerbutton); sysViewerButton = (Button) findViewById(R.id.sysviewerbutton); helpButton = (Button) findViewById(R.id.helpbutton); serviceStartButton.setOnClickListener(serviceStartButtonListener); sysViewerButton.setOnClickListener(sysViewerButtonListener); appViewerButton.setOnClickListener(appViewerButtonListener); helpButton.setOnClickListener(helpButtonListener); if (counterService != null) { serviceStartButton.setText("Stop Profiler"); appViewerButton.setEnabled(true); sysViewerButton.setEnabled(true); } else { serviceStartButton.setText("Start Profiler"); appViewerButton.setEnabled(false); sysViewerButton.setEnabled(false); } }
From source file:net.majorkernelpanic.spydroid.ClientActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.client);//w w w . j a v a 2 s . c om editTextIP = (EditText) findViewById(R.id.server_ip); layoutContainer = (FrameLayout) findViewById(R.id.video_container); layoutForm = (RelativeLayout) findViewById(R.id.form); layoutControl = (RelativeLayout) findViewById(R.id.control); progressBar = (ProgressBar) findViewById(R.id.progress); audioStream = new MediaPlayer(); // Initiate connection with client findViewById(R.id.button_connect).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Editor editor = settings.edit(); editor.putString("last_server_ip", editTextIP.getText().toString()); editor.commit(); layoutForm.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); getCurrentConfiguration(); } }); // Interrupt connection with the client findViewById(R.id.button_stop).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { stopStreaming(); layoutControl.setVisibility(View.GONE); layoutForm.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); } }); // Show configuration panel findViewById(R.id.button_config).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { findViewById(R.id.settings).setVisibility(View.VISIBLE); } }); findViewById(R.id.reconnect).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { findViewById(R.id.settings).setVisibility(View.GONE); updateSettings(); } }); // Resolution Spinner spinner = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.videoResolutionArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); // Framerate spinner = (Spinner) findViewById(R.id.spinner2); adapter = ArrayAdapter.createFromResource(this, R.array.videoFramerateArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Bitrate spinner = (Spinner) findViewById(R.id.spinner3); adapter = ArrayAdapter.createFromResource(this, R.array.videoBitrateArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Video Encoder spinner = (Spinner) findViewById(R.id.spinner4); adapter = ArrayAdapter.createFromResource(this, R.array.videoEncoderArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Audio Encoder spinner = (Spinner) findViewById(R.id.spinner5); adapter = ArrayAdapter.createFromResource(this, R.array.audioEncoderArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); settings = PreferenceManager.getDefaultSharedPreferences(this); editTextIP.setText(settings.getString("last_server_ip", "192.168.0.107")); }
From source file:com.commonslab.commonslab.Fragments.UploadToCommonsFragment.java
private void setupView() { uploadTitleTextView = (AutoCompleteTextView) getActivity().findViewById(R.id.upload_title); uploadDescriptionTextView = (AutoCompleteTextView) getActivity().findViewById(R.id.upload_description); uploadCommentTextView = (AutoCompleteTextView) getActivity().findViewById(R.id.upload_comment); upload_license = (Spinner) getActivity().findViewById(R.id.upload_license); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.Licenses, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); upload_license.setAdapter(adapter);/* w w w . j a va 2 s.co m*/ coverImage = (ImageView) getActivity().findViewById(R.id.uploadImageView); coverImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mediaType == Media.AUDIO) { if (mediaPlayer == null) { try { playAudio(contributionPath); } catch (IOException e) { e.printStackTrace(); } } else if (mediaPlayer != null) { mediaPlayer.stop(); //start playing from the start try { playAudio(contributionPath); } catch (IOException e) { e.printStackTrace(); } } } else if (mediaType == Media.VIDEO) { playVideo(); } else { //Image Intent intent = new Intent(getActivity(), ImageDetailsActivity.class); intent.putExtra("ImageURL", contributionPath); startActivity(intent); } } }); cancelButton = (Button) getActivity().findViewById(R.id.upload_cancel); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { exitFragment(); } }); uploadButton = (Button) getActivity().findViewById(R.id.uploadButton); uploadButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { uploadMedia(); } }); setFonts(); }
From source file:com.wishlist.Wishlist.java
/** Called when the activity is first created. */ @Override//from w w w . ja va2s. co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see FbAPIs.java"); return; } setContentView(R.layout.wishlist); mHandler = new Handler(); mText = (TextView) Wishlist.this.findViewById(R.id.txt); mUserPic = (ImageView) Wishlist.this.findViewById(R.id.user_pic); mProduceName = (EditText) Wishlist.this.findViewById(R.id.product_name); mWishlistSpinner = (Spinner) Wishlist.this.findViewById(R.id.wishlist_spinner); mPlacesListSpinner = (Spinner) Wishlist.this.findViewById(R.id.location); image = (ImageView) Wishlist.this.findViewById(R.id.itemPhoto); image.setImageResource(R.drawable.camera); image.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_PICK, (MediaStore.Images.Media.EXTERNAL_CONTENT_URI)); startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE); } }); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.wishlist_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWishlistSpinner.setAdapter(adapter); mPlacesListSpinner.setClickable(false); mAddtoTimeline = (Button) Wishlist.this.findViewById(R.id.timeline); mAddtoTimeline.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!Utility.mFacebook.isSessionValid()) { showToast(getString(R.string.must_login)); return; } mProductName = mProduceName.getText().toString(); if (mProductName == null || TextUtils.isEmpty(mProductName)) { showToast(getString(R.string.enter_product_name)); return; } if (imageBytes == null) { showToast(getString(R.string.take_product_photo)); return; } /* * Upload photo first and then publish to the timeline after successful photo upload. */ uploadPhoto(); } }); /* * Initalize Facebook Object, retrieve access token and layout the Login button */ initFacebook(); }
From source file:org.gnucash.android.ui.report.ReportsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { mReportType = (ReportType) savedInstanceState.getSerializable(STATE_REPORT_TYPE); }//from ww w.j a va 2 s. c om super.onCreate(savedInstanceState); mTransactionsDbAdapter = TransactionsDbAdapter.getInstance(); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.report_time_range, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mTimeRangeSpinner.setAdapter(adapter); mTimeRangeSpinner.setOnItemSelectedListener(this); mTimeRangeSpinner.setSelection(1); ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(this, R.array.report_account_types, android.R.layout.simple_spinner_item); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAccountTypeSpinner.setAdapter(dataAdapter); mAccountTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { switch (position) { default: case 0: mAccountType = AccountType.EXPENSE; break; case 1: mAccountType = AccountType.INCOME; } updateAccountTypeOnFragments(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { //nothing to see here, move along } }); mReportsOverviewFragment = new ReportsOverviewFragment(); if (savedInstanceState == null) { loadFragment(mReportsOverviewFragment); } }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override/* w w w. ja va 2 s . c o m*/ public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beacon.expectedStability != null && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beacon.status = Beacon.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beacon.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:com.example.android.pets.EditorActivity.java
/** * Setup the dropdown spinner that allows the user to select the gender of the pet. *///from ww w . j a va 2 s . co m private void setupSpinner() { // Create adapter for spinner. The list options are from the String array it will use // the spinner will use the default layout ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options, android.R.layout.simple_spinner_item); // Specify dropdown layout style - simple list view with 1 item per line genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); // Apply the adapter to the spinner mGenderSpinner.setAdapter(genderSpinnerAdapter); // Set the integer mSelected to the constant values mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)) { if (selection.equals(getString(R.string.gender_male))) { mGender = PetEntry.GENDER_MALE; } else if (selection.equals(getString(R.string.gender_female))) { mGender = PetEntry.GENDER_FEMALE; } else { mGender = PetEntry.GENDER_UNKNOWN; } } } // Because AdapterView is an abstract class, onNothingSelected must be defined @Override public void onNothingSelected(AdapterView<?> parent) { mGender = PetEntry.GENDER_UNKNOWN; } }); }