List of usage examples for android.support.v4.widget SimpleCursorAdapter SimpleCursorAdapter
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
From source file:com.ptts.fragments.RouteListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context android.R.layout.simple_list_item_activated_2, // Layout for individual rows null, // Cursor FROM_COLUMNS, // Cursor columns to use TO_FIELDS, // Layout fields to use 0 // No flags );/* w w w .j a va 2 s .co m*/ mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { // Let SimpleCursorAdapter handle other fields automatically return false; } }); setListAdapter(mAdapter); setEmptyText(getText(R.string.loading)); getLoaderManager().initLoader(0, null, this); }
From source file:br.com.bioscada.apps.biotracks.fragments.ShareTrackDialogFragment.java
@Override protected Dialog createDialog() { FragmentActivity fragmentActivity = getActivity(); accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE); if (accounts.length == 0) { return new AlertDialog.Builder(fragmentActivity).setMessage(R.string.send_google_no_account_message) .setTitle(R.string.send_google_no_account_title).setPositiveButton(R.string.generic_ok, null) .create();//from w w w.j a va2 s.c o m } // Get all the views View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null); publicCheckBox = (CheckBox) view.findViewById(R.id.share_track_public); inviteCheckBox = (CheckBox) view.findViewById(R.id.share_track_invite); multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.share_track_emails); accountSpinner = (Spinner) view.findViewById(R.id.share_track_account); // Setup publicCheckBox publicCheckBox.setChecked(PreferencesUtils.getBoolean(fragmentActivity, R.string.share_track_public_key, PreferencesUtils.SHARE_TRACK_PUBLIC_DEFAULT)); // Setup inviteCheckBox inviteCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { multiAutoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); inviteCheckBox.setChecked(PreferencesUtils.getBoolean(fragmentActivity, R.string.share_track_invite_key, PreferencesUtils.SHARE_TRACK_INVITE_DEFAULT)); // Setup multiAutoCompleteTextView multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity, R.layout.add_emails_item, getAutoCompleteCursor(fragmentActivity, null), new String[] { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA); return cursor.getString(index).trim(); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return getAutoCompleteCursor(getActivity(), constraint); } }); multiAutoCompleteTextView.setAdapter(adapter); // Setup accountSpinner accountSpinner.setVisibility(accounts.length > 1 ? View.VISIBLE : View.GONE); AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts); return new AlertDialog.Builder(fragmentActivity).setNegativeButton(R.string.generic_cancel, null) .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { FragmentActivity context = getActivity(); if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) { Toast.makeText(context, R.string.share_track_no_selection, Toast.LENGTH_LONG).show(); return; } String acl = multiAutoCompleteTextView.getText().toString().trim(); if (!publicCheckBox.isChecked() && acl.equals("")) { Toast.makeText(context, R.string.share_track_no_emails, Toast.LENGTH_LONG).show(); return; } PreferencesUtils.setBoolean(context, R.string.share_track_public_key, publicCheckBox.isChecked()); PreferencesUtils.setBoolean(context, R.string.share_track_invite_key, inviteCheckBox.isChecked()); Account account = accounts.length > 1 ? accounts[accountSpinner.getSelectedItemPosition()] : accounts[0]; AccountUtils.updateShareTrackAccountPreference(context, account); caller.onShareTrackDone(getArguments().getLong(KEY_TRACK_ID), publicCheckBox.isChecked(), acl, account); } }).setTitle(R.string.share_track_title).setView(view).create(); }
From source file:com.iaraby.template.view.fragment.ListFrag.java
private void populateList() { String[] from = null;//www.j a v a 2 s . com if (isFav) { from = new String[] { Beans.Favorite.COL_TITLE }; } else { from = new String[] { Beans.Category.COL_NAME }; } //check if fav or list int[] to = { R.id.list_item_text }; int layoutId = R.layout.list_item; if (Preferences.getInstance(getActivity()).isRTL()) layoutId = R.layout.list_item_right; getLoaderManager().initLoader(1, null, this); adapter = new SimpleCursorAdapter(getActivity(), layoutId, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); adapter.setViewBinder(new Binder()); setListAdapter(adapter); adapter.notifyDataSetChanged(); }
From source file:net.potterpcs.recipebook.RecipeViewer.java
@SuppressWarnings("deprecation") @Override//from w w w .j ava 2s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.recipeviewer); app = (RecipeBook) getApplication(); data = app.getData(); preferences = PreferenceManager.getDefaultSharedPreferences(this); photoPref = preferences.getBoolean(getResources().getString(R.string.prefphotokey), true); dirPhotoPref = preferences.getBoolean(getResources().getString(R.string.prefdirphotokey), true); // Fill in the UI rvname = (TextView) findViewById(R.id.rvname); rvcreator = (TextView) findViewById(R.id.rvcreator); rvserving = (TextView) findViewById(R.id.rvserving); rvtime = (TextView) findViewById(R.id.rvtime); rvrating = (RatingBar) findViewById(R.id.rvrating); lvingredients = (GridView) findViewById(R.id.ingredients); lvdirections = (ListView) findViewById(R.id.directions); rid = Long.parseLong(getIntent().getData().getLastPathSegment()); RecipeData.Recipe r = data.getSingleRecipeObject(rid); rvname.setText(r.name); rvcreator.setText(r.creator); rvserving.setText(Integer.toString(r.serving)); rvtime.setText(DateUtils.formatElapsedTime(r.time)); rvrating.setRating(r.rating); photoUri = r.photo; if (photoPref && photoUri != null && !photoUri.equals("")) { rvphoto = (FrameLayout) findViewById(R.id.photofragment); ImageView iv = new ImageView(this); setOrDownloadImage(iv, photoUri); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); PhotoDialog pd = PhotoDialog.newInstance(photoUri); pd.show(ft, "dialog"); } }); rvphoto.addView(iv); } directionsAdapter = new SimpleCursorAdapter(this, R.layout.recipedirectionrow, null, DIRECTIONS_FIELDS, DIRECTIONS_IDS, 0); directionsAdapter.setViewBinder(new DirectionViewBinder(this)); lvdirections.setAdapter(directionsAdapter); lvdirections.setDividerHeight(0); ingredientsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, INGREDIENTS_FIELDS, INGREDIENTS_IDS, 0); lvingredients.setAdapter(ingredientsAdapter); // Set up sharing intent shareIntent = ShareCompat.IntentBuilder.from(this).setSubject(r.name).setText(r.toText(this)) .setType("text/plain"); }
From source file:com.idt.ontomedia.geoconsum.RegulationSearchActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_regulation); //Link elements mTextViewAutonomousCommunity = (TextView) findViewById(R.id.textView_AutonomousRegion_regulation); mSpinnerAutonomousCommunity = (Spinner) findViewById(R.id.spinner_AutonomousRegion_regulation); mSpinnerSubtypeOfRegulation = (Spinner) findViewById(R.id.spinner_subtype_regulation); mSpinnerTypeOfRegulation = (Spinner) findViewById(R.id.spinner_type_regulation); //Lock Autonomous Community to Catalunya mSpinnerAutonomousCommunity.setEnabled(false); mSpinnerTypeOfRegulation.setOnItemSelectedListener(new OnItemSelectedListener() { @Override// ww w . jav a2 s .c o m public void onItemSelected(AdapterView<?> _containerView, View _itemView, int _position, long _id) { mSpinnerAutonomousCommunity.setSelection(mAutonomousCommunityPosition); if (mSpinnerTypeOfRegulation.getSelectedItemId() == 1) { mSpinnerAutonomousCommunity.setSelection(mAutonomousCommunityPosition); mSpinnerAutonomousCommunity.setVisibility(View.VISIBLE); mTextViewAutonomousCommunity.setVisibility(View.VISIBLE); } else { mSpinnerAutonomousCommunity.setVisibility(View.GONE); mTextViewAutonomousCommunity.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); Button buttonSearch = (Button) findViewById(R.id.buttonSearch_regulation); buttonSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View _view) { Intent intent = new Intent(getBaseContext(), ListRegulationsActivity.class); intent.putExtra(EXTRA_TYPE, (int) mSpinnerTypeOfRegulation.getSelectedItemId()); intent.putExtra(EXTRA_SUBTYPE, (int) mSpinnerSubtypeOfRegulation.getSelectedItemId()); if (mSpinnerAutonomousCommunity.getVisibility() == View.VISIBLE) { intent.putExtra(EXTRA_AUTONOMOUS_COMMUNITY, (int) mSpinnerAutonomousCommunity.getSelectedItemId()); } startActivity(intent); } }); mAdapterTypeOfRegulation = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null, TYPE_OF_LOCATION_COLUMNS_FROM, VIEWS_TO, 0); mAdapterTypeOfRegulation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerTypeOfRegulation.setAdapter(mAdapterTypeOfRegulation); mAdapterSubtypeOfRegulation = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null, TYPE_OF_LOCATION_COLUMNS_FROM, VIEWS_TO, 0); mAdapterSubtypeOfRegulation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerSubtypeOfRegulation.setAdapter(mAdapterSubtypeOfRegulation); mAdapterAutonomousCommunity = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null, COLUMNS_FROM, VIEWS_TO, 0); mAdapterAutonomousCommunity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerAutonomousCommunity.setAdapter(mAdapterAutonomousCommunity); getSupportLoaderManager().initLoader(TYPE_OF_REGULATION_LOADER_ID, null, new TypeOfRegulationCursorLoaderCallback()); getSupportLoaderManager().initLoader(SUBTYPE_OF_REGULATION_LOADER_ID, null, new SubtypeOfRegulationCursorLoaderCallback()); getSupportLoaderManager().initLoader(AUTONOMOUS_COMMUNITY_LOADER_ID, null, new AutonomousCommunityCursorLoaderCallback()); }
From source file:com.election.US.basicsyncadapter.EntryListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context android.R.layout.simple_list_item_activated_2, // Layout for individual rows null, // Cursor FROM_COLUMNS, // Cursor columns to use TO_FIELDS, // Layout fields to use 0 // No flags );/*from w w w. ja v a 2 s . c o m*/ mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { if (i == COLUMN_PUBLISHED) { // Convert timestamp to human-readable date Time t = new Time(); t.set(cursor.getLong(i)); ((TextView) view).setText(t.format("%Y-%m-%d %H:%M")); return true; } else { // Let SimpleCursorAdapter handle other fields automatically return false; } } }); setListAdapter(mAdapter); setEmptyText(getText(R.string.loading)); getLoaderManager().initLoader(0, null, this); }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.LoginFragment.java
/** * Set the login fragment layout and initialize the login logic * @param inflater inflater object to inflate the layout * @param container the parent view container * @param savedInstanceState fragment state bundle * @return the inflated view/*from w ww.j a v a 2 s .c om*/ */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // inflate the login fragment layout View mainView = inflater.inflate(R.layout.login_fragment, container, false); // bind the elements to the view ButterKnife.bind(this, mainView); if (savedInstanceState == null) { // check if there is a newer build of the app available Utility.checkForUpdate(getActivity(), UPDATE_FRAGMENT_TAG, true); // TODO: if there is no internet connection and accounts were never loaded: keep checking for an internet connection and try again // check time in hours since last fetched the accounts SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); long diffInHours = getResources() .getInteger(R.integer.makkelijkemarkt_api_accounts_fetch_interval_hours); if (settings.contains(getContext().getString(R.string.sharedpreferences_key_accounts_last_fetched))) { long lastFetchTimestamp = settings .getLong(getContext().getString(R.string.sharedpreferences_key_accounts_last_fetched), 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // update the local accounts by reloading them from the api if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_accounts_fetch_interval_hours)) { // show the progressbar mAccountsProgressBar.setVisibility(View.VISIBLE); // call the api ApiGetAccounts getAccounts = new ApiGetAccounts(getContext()); if (!getAccounts.enqueue()) { mAccountsProgressBar.setVisibility(View.GONE); } } } // create an adapter for the account spinner mAccountsAdapter = new SimpleCursorAdapter(getContext(), android.R.layout.simple_list_item_activated_1, null, new String[] { MakkelijkeMarktProvider.Account.COL_NAAM }, new int[] { android.R.id.text1 }, 0); // attach the adapter to the account spinner mAccount.setAdapter(mAccountsAdapter); // initiate loading the accounts from the database getLoaderManager().initLoader(ACCOUNTS_LOADER, null, this); // disable all caps for the button title mLoginButton.setTransformationMethod(null); // create the login progress dialog mLoginProcessDialog = new ProgressDialog(getContext()); mLoginProcessDialog.setIndeterminate(true); mLoginProcessDialog .setIndeterminateDrawable(ContextCompat.getDrawable(getContext(), R.drawable.progressbar_circle)); mLoginProcessDialog.setMessage(getString(R.string.login) + "..."); mLoginProcessDialog.setCancelable(false); return mainView; }
From source file:com.idt.ontomedia.geoconsum.NearPlacesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.places_near); //Initialize some values mNearPlaceList = new ArrayList<NearPlace>(); mDistances = getResources().getStringArray(R.array.distances_to_places); mSpinnerTypeOfLocation = (Spinner) findViewById(R.id.spinner1); mSpinnerTypeOfLocation.setOnItemSelectedListener(new OnItemSelectedListener() { @Override/*from w w w.j av a 2s . c o m*/ public void onItemSelected(AdapterView<?> _containerView, View _itemView, int _position, long _id) { getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged(); } @Override public void onNothingSelected(AdapterView<?> _containerView) { } }); mSpinnerDistances = (Spinner) findViewById(R.id.spinner2); mSpinnerDistances.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> _containerView, View _itemView, int _position, long _id) { getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged(); } @Override public void onNothingSelected(AdapterView<?> _containerView) { } }); ImageButton buttonUpdate = (ImageButton) findViewById(R.id.buttonUpdate); buttonUpdate.setOnClickListener(new OnClickListener() { @Override public void onClick(View _view) { getSupportLoaderManager().getLoader(NEAR_PLACES_LOADER_ID).onContentChanged(); } }); // Configure the adapter and set the spinner of distances // This is a programatically operation because we can't modify the text color // with the use of "entries" in the xml file. We define an ArrayAdapter and specify the layout of this to avoid // the default layout with the normal text style (black and normal) ArrayAdapter<String> arrayAdapterDistances = new ArrayAdapter<String>(this, R.layout.my_spinner_layout, mDistances); arrayAdapterDistances.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerDistances.setAdapter(arrayAdapterDistances); // Configure the adapter and set the spinner of types of Places // This is a programatically operation because we can't modify the text color // with the use of "entries" in the xml file. We define an ArrayAdapter and specify the layout of this to avoid // the default layout with the normal text style (black and normal) mAdapterTypeOfLocation = new SimpleCursorAdapter(this, R.layout.my_spinner_layout, null, COLUMNS_FROM, VIEWS_TO, 0); mAdapterTypeOfLocation.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerTypeOfLocation.setAdapter(mAdapterTypeOfLocation); mSpinnerTypeOfLocation.setSelection(mTypeOfLocationPosition, true); //Create the adapter and fill the place list with the real distances mNearPlacesAdapter = new NearPlacesAdapter(this, mNearPlaceList); mListViewNearPlaces = (ListView) findViewById(R.id.listViewNearPlaces); mListViewNearPlaces.setAdapter(mNearPlacesAdapter); mListViewNearPlaces.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> _containerView, View _itemView, int _position, long _id) { Intent intent = new Intent(); intent.setClass(getBaseContext(), PlaceDetailActivity.class); intent.putExtra(ListPlacesFragment.EXTRA_ID_KEY, mNearPlaceList.get(_position).getId()); startActivity(intent); } }); getSupportLoaderManager().initLoader(TYPE_OF_LOCATION_LOADER_ID, null, new TypeOfLocationCursorLoaderCallback()); getSupportLoaderManager().initLoader(NEAR_PLACES_LOADER_ID, null, new NearPlacesCursorLoaderCallback()); }
From source file:com.example.locationprovider.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connect to the main UI setContentView(R.layout.activity_main); /*/*from w w w . j a v a 2s .c o m*/ * Get handles to UI elements */ // Connection status reporting field mConnectionStatus = (TextView) findViewById(R.id.connection_status); // App status reporting field mAppStatus = (TextView) findViewById(R.id.app_status); // Pause interval entry field mPauseInterval = (EditText) findViewById(R.id.pause_value); // Send interval entry field mSendInterval = (EditText) findViewById(R.id.send_interval_value); // Activity indicator that appears while a test run is underway mActivityIndicator = (ProgressBar) findViewById(R.id.testing_activity_indicator); // Instantiate a broadcast receiver for Intents coming from the Service mMessageReceiver = new ServiceMessageReceiver(); /* * Filter incoming Intents from the Service. Receive only Intents with a particular action * value. */ IntentFilter filter = new IntentFilter(LocationUtils.ACTION_SERVICE_MESSAGE); /* * Restrict detection of Intents. Only Intents from other components in this app are * detected. */ LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter); // Instantiate the Intent that starts SendMockLocationService mRequestIntent = new Intent(this, SendMockLocationService.class); /* * */ mAdapter = new SimpleCursorAdapter(this, R.layout.listitem, null, new String[] { "name", "latitude", "longitude" }, new int[] { R.id.name, R.id.latitude, R.id.longitude }, 0); ((ListView) findViewById(R.id.listview)).setAdapter(mAdapter); ((ListView) findViewById(R.id.listview)).setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { mCursor.moveToPosition(position); getContentResolver().delete(MockLocationProvider.uri, "_id=?", new String[] { String.valueOf(mCursor.getInt(mCursor.getColumnIndex(GV._ID))) }); return false; } }); getSupportLoaderManager().initLoader(0, null, this); findViewById(R.id.add).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = ((EditText) findViewById(R.id.name)).getText().toString(); double lat = Double.parseDouble(((EditText) findViewById(R.id.latitude)).getText().toString()); double lng = Double.parseDouble(((EditText) findViewById(R.id.longitude)).getText().toString()); getContentResolver().insert(MockLocationProvider.uri, new MockLocationModel().getContentValues(name, lat, lng, 3.0f)); } }); }
From source file:se.chalmers.watchme.ui.TagListFragment.java
/** * Set up adapter and set adapter.//from w w w. j a va 2 s .c o m */ private void setUpAdapter() { // Bind name column in the table Tags to the text field in each row. String[] from = new String[] { TagsTable.COLUMN_NAME }; int[] to = new int[] { android.R.id.text1 }; getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this); super.setAdapter( new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1, null, from, to, 0)); }