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:net.wrolf.android.outages.OutageListFragment.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 www.ja v a 2 s . com*/ mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { // TODO format time return false; // if (i == COLUMN_TIME) { // // 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:planets.position.LunarEclipse.java
private void fillData() { Cursor eclCursor = cr.query(PlanetsDbProvider.LUNAR_URI, projection, null, null, "penBegin"); String[] from = new String[] { "eclipseDate", "eclipseType", "local" }; int[] to = new int[] { R.id.eclDate, R.id.eclType, R.id.eclLocal }; // Now create a simple cursor adapter and set it to display cursorAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.ecl_row, eclCursor, from, to, 0); // Binds the 'local' field in the db to the checked attribute for the // CheckBox/* w w w . j ava 2 s . c o m*/ cursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == 3) { CheckBox cb = (CheckBox) view; cb.setChecked(cursor.getInt(3) > 0); return true; } return false; } }); eclipseList.setAdapter(cursorAdapter); }
From source file:planets.position.SolarEclipse.java
private void fillData() { Cursor eclCursor = cr.query(PlanetsDbProvider.SOLAR_URI, projection, null, null, "globalBeginTime"); String[] from = new String[] { "eclipseDate", "eclipseType", "local" }; int[] to = new int[] { R.id.eclDate, R.id.eclType, R.id.eclLocal }; // Now create a simple cursor adapter and set it to display cursorAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.ecl_row, eclCursor, from, to, 0); // Binds the 'local' field in the db to the checked attribute for the // CheckBox/* www.ja va 2 s .co m*/ cursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == 3) { CheckBox cb = (CheckBox) view; cb.setChecked(cursor.getInt(3) > 0); return true; } return false; } }); eclipseList.setAdapter(cursorAdapter); }
From source file:com.example.android.basicsyncadapter.FeedListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mListView = (ListView) view.findViewById(R.id.list_view); mEmpty = view.findViewById(R.id.empty); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context R.layout.list_item, // Layout for individual rows null, // Cursor new String[] { // Cursor columns to use FeedContract.Entry.COLUMN_NAME_TITLE, FeedContract.Entry.COLUMN_NAME_PUBLISHED }, new int[] { // Layout fields to use R.id.title, R.id.date }, 0 // No flags );// ww w. jav a2 s .co 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; } } }); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Load an article in the default browser when selected by the user. // Get a URI for the selected item, then start an Activity that displays the URI. Any // Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will // be a browser. // Get the item at the selected position, in the form of a Cursor. Cursor c = (Cursor) mAdapter.getItem(position); // Get the link to the article represented by the item. String articleUrlString = c.getString(COLUMN_URL_STRING); if (articleUrlString == null) { Log.e(TAG, "Attempt to launch entry with null link"); return; } Log.i(TAG, "Opening URL: " + articleUrlString); // Get a Uri object for the URL string Uri articleURL = Uri.parse(articleUrlString); Intent i = new Intent(Intent.ACTION_VIEW, articleURL); startActivity(i); } }); getLoaderManager().initLoader(0, null, this); }
From source file:planets.position.ViewWhatsUp.java
private void fillData(int list) { filter = list;/*from ww w . ja v a 2 s. c o m*/ Cursor plCursor; if (list == 1) { plCursor = cr.query(PlanetsDbProvider.PLANETS_URI, projection, "alt > 0.0", null, null); } else { plCursor = cr.query(PlanetsDbProvider.PLANETS_URI, projection, "alt > 0.0 AND mag <= 6", null, null); } String[] from = new String[] { "name", "az", "alt", "mag" }; int[] to = new int[] { R.id.list2, R.id.list3, R.id.list4, R.id.list5 }; cursorAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.planet_row, plCursor, from, to, 0); planetsList.setAdapter(cursorAdapter); }
From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Intent intent = new Intent(); intent.setData(Notes.CONTENT_URI); getListView().setOnCreateContextMenuListener(this); mNoteListAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_note, null, new String[] { Notes.TITLE, Notes.MODIFIED_DATE }, new int[] { R.id._title, R.id._created_time }, 0);//from w ww . jav a2 s.c o m mNoteListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == NotesQuery.MODIFIED_DATE) { long modified = cursor.getLong(NotesQuery.MODIFIED_DATE); Date date = new Date(modified); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String text = simpleDateFormat.format(date); ((TextView) view).setText(text); return true; } return false; } }); mNoteListView.setAdapter(mNoteListAdapter); mManager = getLoaderManager(); mManager.restartLoader(NotesQuery.LOADER_ID, null, mLoaderCallbacks); }
From source file:com.mstoyanov.music_lessons.ScheduleFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true);/*from ww w . j a va2 s.c om*/ // get the weekday from the MainActivity: weekday = getArguments().getString("WEEKDAY"); ((TextView) view.findViewById(R.id.weekday)).setText(weekday); selectionArgs_lessons[0] = weekday; // determine the current layout: View actionsView = getActivity().findViewById(R.id.lesson_details_pane); dualPane = actionsView != null && actionsView.getVisibility() == View.VISIBLE; String[] fromColumns = new String[] { "timeFrom", "timeTo", "firstName", "lastName" }; int[] toViews = new int[] { R.id.timeFrom, R.id.timeTo, R.id.firstName, R.id.lastName }; lessonsAdapter = new SimpleCursorAdapter(getActivity(), R.layout.lesson_list_item, // layout null, // no cursor is created yet fromColumns, // columns toViews, // UI controls 0 // flags ); lessonsList = (ListView) view.findViewById(R.id.lessons_list); lessonsList.setOnItemClickListener(this); lessonsList.setAdapter(lessonsAdapter); // in dual pane mode, the controls from the LessonDetailsActivity // appear in the right column of the ScheduleFragment: if (dualPane) { if (savedInstanceState != null) { selectedLesson = savedInstanceState.getInt("SELECTED_LESSON", 0); } firstNameLabel = ((TextView) view.findViewById(R.id.label_fname_schedule)); firstNameTextView = ((TextView) view.findViewById(R.id.fname_schedule)); lastNameLabel = ((TextView) view.findViewById(R.id.label_lname_schedule)); lastNameTextView = ((TextView) view.findViewById(R.id.lname_schedule)); actionsList = (ListView) view.findViewById(R.id.actions_list); actionsList.setOnItemClickListener(this); actions = new ArrayList<Actions>(); actionsAdapter = new ActionsAdapter(getActivity(), actions); actionsList.setAdapter(actionsAdapter); } }
From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); int loader_id = getArguments().getInt(ARG_SECTION_NUMBER); 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 ww. j av a 2s . com 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(loader_id, null, this); }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void InitializeView() { // Set up event handlers for the task list ListView listView = (ListView) findViewById(R.id.task_list); listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(this); listView.setLongClickable(true);//from ww w . j ava2 s . c o m // Get a cursor to populate the UI Cursor cursor = mDB.GetCursor(); String from[] = { "NAME", "DUE_DATE" }; int to[] = { R.id.task_name_edit, R.id.task_due_date }; mAdapter = new SimpleCursorAdapter(this, R.layout.task_list_element, cursor, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); // Set up a ViewBinder to convert the due date to something more human-friendly mAdapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { try { if (columnIndex == 2) { Calendar dueDate = TaskDatabase.ConvertIntToDate(cursor.getInt(columnIndex)); TextView dueDateView = (TextView) view; SetFriendlyDueDateText(dueDateView, dueDate); return true; } } catch (Exception e) { AlertDialog.Builder builder = new AlertDialog.Builder(TaskListActivity.this); AlertDialog dlg = builder.setTitle("Database error!").setMessage(e.getMessage()).create(); dlg.show(); } return false; } }); listView.setAdapter(mAdapter); }
From source file:org.gnucash.android.ui.transactions.TransactionsActivity.java
/** * Set up action bar navigation list and listener callbacks */// w w w . ja v a2s . co m private void setupActionBarNavigation() { // set up spinner adapter for navigation list mAccountsDbAdapter = new AccountsDbAdapter(this); Cursor accountsCursor = mAccountsDbAdapter.fetchAllAccounts(); mSpinnerAdapter = new SimpleCursorAdapter(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item, accountsCursor, new String[] { DatabaseHelper.KEY_NAME }, new int[] { android.R.id.text1 }, 0); ((ResourceCursorAdapter) mSpinnerAdapter).setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(mSpinnerAdapter, mTransactionListNavigationListener); updateNavigationSelection(); }