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.facebook.android.MainPage.java
/** Called when the activity is first created. */ @Override/*from w w w. j av a 2 s . c om*/ 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 Example.java"); } setContentView(R.layout.main); mMovieNameInput = (EditText) findViewById(R.id.title); mMediaSpinner = (Spinner) findViewById(R.id.media); mSearchButton = (Button) findViewById(R.id.search); mFacebook = new Facebook(APP_ID); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); // set up the Spinner for the media list selection ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.media_list, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mMediaSpinner.setAdapter(adapter); //for search button final Context context = this; mSearchButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String servletURL; String movieName = mMovieNameInput.getText().toString(); // check the input text of movie, if the text is empty give user alert movieName = movieName.trim(); if (movieName.length() == 0) { Toast toast = Toast.makeText(context, "Please enter a movie name", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 70); toast.show(); } // if movie name is not empty else { // remove any extra whitespace movieName = movieName.replaceAll("\\s+", "+"); String mediaList = mMediaSpinner.getSelectedItem().toString(); if (mediaList.equals("Feature Film")) { mediaList = "feature"; } mediaList = mediaList.replaceAll("\\s+", "+"); // construct the query string // construct the final URL to Servlet //String servletString = "?" + "title=" + movieName + "&" + "title_type=" + mediaList; //servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie" //+ servletString; //String servletString = "?" + "title=" + movieName + "&" + "media=" + mediaList; //servletURL = "http://cs-server.usc.edu:34404/examples/servlet/HelloWorldExample?title=" + movieName + "&" + "media=" + mediaList; //+ servletString; servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie?title=" + movieName + "&" + "title_type=" + mediaList; BufferedReader in = null; try { // REFERENCE: this part of code is modified from: // "Example of HTTP GET Request using HttpClient in Android" // http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/ // get response (JSON string) from Servlet HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(servletURL)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String page = sb.toString(); //test for JSON string /*LinearLayout lView = new LinearLayout(context); TextView myText = new TextView(context); myText.setText(page); lView.addView(myText); setContentView(lView);*/ // convert the JSON string to real JSON and get out the movie JSON array // to check if there is any movie data JSONObject finalJson; JSONObject movieJson; JSONArray movieJsonArray; finalJson = new JSONObject(page); movieJson = finalJson.getJSONObject("results"); //System.out.println(movieJson); movieJsonArray = movieJson.getJSONArray("result"); // if the response contains some movie data if (movieJsonArray.length() != 0) { // start the ListView activity, and pass the JSON string to it Intent intent = new Intent(context, MovieListActivity.class); intent.putExtra("finalJson", page); startActivity(intent); } // if the response does not contain any movie data, // show user that there is no result for this search else { Toast toast = Toast.makeText(getBaseContext(), "No movie found for this search", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } } catch (URISyntaxException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } } }); }
From source file:me.diskstation.ammon.gpsrunner.ui.CalendarFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_calendar, container, false); mSpinnerLayout = inflater.inflate(R.layout.spinner_header, null); mListView = (ListView) view.findViewById(R.id.runsListView); mListView.addHeaderView(mSpinnerLayout); spinnerSelections = new Bundle(); //initializing spinners with ArrayAdapters getting values from string arrays yearSpinner = (Spinner) mSpinnerLayout.findViewById(R.id.yearSpinner); ArrayAdapter<CharSequence> yearAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.years_array, R.layout.spinner_item);/* ww w .j av a 2s . c o m*/ yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); yearSpinner.setAdapter(yearAdapter); yearSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int year = position + 2015; spinnerSelections.putInt("spinner_selection_year", year); refreshList(getRuns(spinnerSelections)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); Calendar c = Calendar.getInstance(); int currentYear = c.get(Calendar.YEAR); yearSpinner.setSelection(currentYear - 2015); spinnerSelections.putInt("spinner_selection_year", currentYear); monthSpinner = (Spinner) mSpinnerLayout.findViewById(R.id.monthSpinner); ArrayAdapter<CharSequence> monthAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.months_array, R.layout.spinner_item); monthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); monthSpinner.setAdapter(monthAdapter); monthSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { spinnerSelections.putInt("spinner_selection_month", position); refreshList(getRuns(spinnerSelections)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); int currentMonth = c.get(Calendar.MONTH); //starts with 0 monthSpinner.setSelection(currentMonth); //also starts with 0 spinnerSelections.putInt("spinner_selection_month", currentMonth); mAdapter = new RunsListAdapter(getActivity(), getRuns(spinnerSelections)); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(this); //mListView.setOnItemLongClickListener(this); //mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); moved to onLongClickListener mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(this); return view; }
From source file:id.nci.stm_9.ImportKeysActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.import_keys); // set actionbar without home button if called from another app ActionBarHelper.setBackButton(this); // set drop down navigation mNavigationStrings = getResources().getStringArray(R.array.import_action_list); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.import_action_list, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(list, this); getSupportActionBar().setDisplayShowTitleEnabled(false); handleActions(savedInstanceState, getIntent()); }
From source file:com.greenapp.wavecast.MapInfographActivity.java
@Override protected void startDemo() { getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(43.652527, -79.38196), 4)); // Set up the spinner/dropdown list Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);/*w w w . j av a 2s.c o m*/ spinner.setOnItemSelectedListener(new SpinnerActivity()); try { mLists.put(getString(R.string.police_stations), new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url))); mLists.put(getString(R.string.medicare), new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url))); } catch (JSONException e) { Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show(); } // Make the handler deal with the map // Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom // intensity from, and the map to draw the heatmap on // radius, gradient and opacity not specified, so default are used }
From source file:dev.ronlemire.data.ListViewFragment.java
public void refresh(int index) { mCurCheckPosition = index;//from w w w. j a va 2 s. c o m // Populate list with our static array of titles. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles, android.R.layout.simple_list_item_single_choice); setListAdapter(adapter); ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); //lv.setItemChecked(mCurCheckPosition, true); //lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition)); }
From source file:com.hardcopy.retrowatch.FiltersFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logs.d(TAG, "# FiltersFragment - onCreateView()"); View rootView = inflater.inflate(R.layout.fragment_filters, container, false); mListFilter = (ListView) rootView.findViewById(R.id.list_filters); if (mFiltersAdapter == null) mFiltersAdapter = new FiltersAdapter(mContext, R.layout.list_filters, null, this); mListFilter.setAdapter(mFiltersAdapter); if (mFiltersCache != null) { mFiltersAdapter.addFilterAll(mFiltersCache); mFiltersAdapter.notifyDataSetChanged(); mFiltersCache = null;//from w w w. j a v a 2s . co m } // Filter object type mSpinnerFilterType = (Spinner) rootView.findViewById(R.id.spinner_type); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.filter_type_array, R.layout.spinner_simple_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerFilterType.setPrompt(mContext.getString(R.string.filter_object_type)); mSpinnerFilterType.setAdapter(adapter); mSpinnerFilterType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mCurrentFilterObject.mType = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Compare type mSpinnerCompareType = (Spinner) rootView.findViewById(R.id.spinner_compare_type); ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(mContext, R.array.filter_matching_type_array, R.layout.spinner_simple_item); adapter2.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerCompareType.setPrompt(mContext.getString(R.string.filter_compare_type)); mSpinnerCompareType.setAdapter(adapter2); mSpinnerCompareType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mCurrentFilterObject.mCompareType = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Replace method mSpinnerReplaceType = (Spinner) rootView.findViewById(R.id.spinner_replace_type); ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(mContext, R.array.filter_replace_type_array, R.layout.spinner_simple_item); adapter3.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerReplaceType.setPrompt(mContext.getString(R.string.filter_replace_type)); mSpinnerReplaceType.setAdapter(adapter3); mSpinnerReplaceType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mCurrentFilterObject.mReplaceType = position; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); // Icon mSpinnerIconType = (Spinner) rootView.findViewById(R.id.spinner_icon_type); ArrayAdapter<CharSequence> adapter4 = ArrayAdapter.createFromResource(mContext, R.array.filter_icon_type_array, R.layout.spinner_simple_item2); adapter4.setDropDownViewResource(R.layout.spinner_dropdown_simple_item); mSpinnerIconType.setPrompt(mContext.getString(R.string.filter_icon)); mSpinnerIconType.setAdapter(adapter4); mSpinnerIconType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mCurrentFilterObject.mIconType = position - 1; } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); mEditOrigin = (EditText) rootView.findViewById(R.id.edit_origin); mEditReplace = (EditText) rootView.findViewById(R.id.edit_replace); mButtonDelete = (Button) rootView.findViewById(R.id.btn_delete); mButtonDelete.setOnClickListener(this); mButtonAdd = (Button) rootView.findViewById(R.id.btn_add); mButtonAdd.setOnClickListener(this); mButtonNew = (Button) rootView.findViewById(R.id.btn_new); mButtonNew.setOnClickListener(this); // Make new filter object and set data on widget makeDefaultFilterObject(); return rootView; }
From source file:dev.ronlemire.dialogs.ListViewFragment.java
public void refresh(int index) { mCurCheckPosition = index;/*from w w w .j av a 2s . co m*/ // Populate list with our static array of titles. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles, android.R.layout.simple_list_item_single_choice); setListAdapter(adapter); ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setItemChecked(mCurCheckPosition, true); lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition)); }
From source file:dev.ronlemire.receivers.ListViewFragment.java
public void refresh(int index) { mCurCheckPosition = index;//from w w w .j a v a 2 s . c om // Populate list with our static array of titles. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles, android.R.layout.simple_list_item_single_choice); setListAdapter(adapter); ListView lv = getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setItemChecked(mCurCheckPosition, true); //lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition)); }
From source file:com.example.android.appusagestatistics.AppUsageStatisticsFragment.java
@Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); mUsageListAdapter = new UsageListAdapter(); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_app_usage); mLayoutManager = mRecyclerView.getLayoutManager(); mRecyclerView.scrollToPosition(0);// w w w . ja va 2 s . c o m mRecyclerView.setAdapter(mUsageListAdapter); mOpenUsageSettingButton = (Button) rootView.findViewById(R.id.button_open_usage_setting); mSpinner = (Spinner) rootView.findViewById(R.id.spinner_time_span); SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.action_list, android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(spinnerAdapter); mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { String[] strings = getResources().getStringArray(R.array.action_list); @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { StatsUsageInterval statsUsageInterval = StatsUsageInterval.getValue(strings[position]); if (statsUsageInterval != null) { List<UsageStats> usageStatsList = getUsageStatistics(statsUsageInterval.mInterval); Collections.sort(usageStatsList, new LastTimeLaunchedComparatorDesc()); updateAppsList(usageStatsList); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.tabinsight.usage.satistics.AppUsageStatisticsFragment.java
@Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); mUsageListAdapter = new UsageListAdapter(); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_app_usage); mLayoutManager = mRecyclerView.getLayoutManager(); mRecyclerView.scrollToPosition(0);//from www . java 2s . co m mRecyclerView.setAdapter(mUsageListAdapter); mOpenUsageSettingButton = (Button) rootView.findViewById(R.id.button_open_usage_setting); mSpinner = (Spinner) rootView.findViewById(R.id.spinner_time_span); SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.action_list, android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(spinnerAdapter); mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { String[] strings = getResources().getStringArray(R.array.action_list); @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { StatsUsageInterval statsUsageInterval = StatsUsageInterval.getValue(strings[position]); if (statsUsageInterval != null) { List<UsageStats> usageStatsList = getUsageStatistics(statsUsageInterval.mInterval); Collections.sort(usageStatsList, new LastTimeLaunchedComparatorDesc()); updateAppsList(usageStatsList); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }