Example usage for android.widget SimpleCursorAdapter setViewBinder

List of usage examples for android.widget SimpleCursorAdapter setViewBinder

Introduction

In this page you can find the example usage for android.widget SimpleCursorAdapter setViewBinder.

Prototype

public void setViewBinder(ViewBinder viewBinder) 

Source Link

Document

Sets the binder used to bind data to views.

Usage

From source file:com.example.edwin.car2charge.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.app_name);/*from   w  w w. ja v a 2 s .  c  om*/

    if (ContextCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, 1);
    }

    if (!isNetworkConnected()) {
        Toast.makeText(getApplicationContext(), "Sorry, no internet connection", Toast.LENGTH_LONG).show();
    }

    else {
        //Toast.makeText(getApplicationContext(), "Yes! network", Toast.LENGTH_LONG).show();
        getContentResolver().delete(CarDataProvider.CONTENT_URI, null, null);
        String[] projection = { CarDatabase.C_ID, CarDatabase.C_ADDRESS, CarDatabase.C_LICENSE,
                CarDatabase.C_BATTERY, CarDatabase.C_DISTANCE, CarDatabase.C_DISTANCE_CP };
        Cursor cars = getContentResolver().query(CarDataProvider.CONTENT_URI, projection, null, null, null);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, cars, FROM, TO);
        adapter.setViewBinder(VIEW_BINDER);
        setListAdapter(adapter);
        carDownloadIntent = new Intent(getApplicationContext(), CarDownloaderService.class);
        gps = new GpsTracker(this, this);
        gps.getLocation();
    }
}

From source file:com.google.android.demos.rss.app.ChannelActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.list_activity);
    ListView listView = (ListView) findViewById(android.R.id.list);
    mEmpty = findViewById(R.id.empty);/*from w  ww  . j a v a  2  s  . c  o  m*/
    mLoading = findViewById(R.id.loading);
    mError = findViewById(R.id.error);
    mError.findViewById(R.id.retry).setOnClickListener(this);

    // Loader from last Activity instance may still be loading
    mLoading.setVisibility(View.VISIBLE);
    mEmpty.setVisibility(View.GONE);
    mError.setVisibility(View.GONE);

    Context context = this;
    int layout = android.R.layout.simple_list_item_1;
    String[] from = { Items.TITLE };
    int[] to = { android.R.id.text1 };
    SimpleCursorAdapter innerAdapter = new SimpleCursorAdapter(context, layout, null, from, to);
    innerAdapter.setViewBinder(this);

    mAdapter = new ChannelAdapter(this);
    mAdapter.registerDataSetObserver(new TitleObserver());
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(this);
    getSupportLoaderManager().initLoader(LOADER_CHANNEL, Bundle.EMPTY, this);
}

From source file:net.callmeike.android.mojowire.ui.PodcastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
    podcastsView = (ListView) inflater.inflate(R.layout.fragment_podcasts, container, false);

    podcastsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  w w  w  . j av  a 2s  .c  o  m
        public void onItemClick(AdapterView<?> parent, View view, int p, long id) {
            selectItem(p);
        }
    });

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.podcast_row, null, FROM, TO,
            0);
    adapter.setViewBinder(new PodcastBinder());
    podcastsView.setAdapter(adapter);

    getLoaderManager().initLoader(PODCAST_TAG, null, this);

    return podcastsView;
}

From source file:com.commonsware.android.fts.QuestionsFragment.java

@Override
public void onViewCreated(View view, Bundle state) {
    super.onViewCreated(view, state);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.row, null,
            new String[] { DatabaseHelper.TITLE, DatabaseHelper.PROFILE_IMAGE },
            new int[] { R.id.title, R.id.icon }, 0);

    adapter.setViewBinder(new QuestionBinder());
    setListAdapter(adapter);// w w w.j a va 2s . c o m
}

From source file:io.github.carlorodriguez.alarmon.MediaListView.java

protected void query(Uri contentUri, String nameColumn, String selection, int rowResId, String[] displayColumns,
        int[] resIDs) {
    this.nameColumn = nameColumn;
    final ArrayList<String> queryColumns = new ArrayList<>(displayColumns.length + 1);
    queryColumns.addAll(Arrays.asList(displayColumns));
    // The ID column is required for the SimpleCursorAdapter.  Make sure to
    // add it if it's not already there.
    if (!queryColumns.contains(BaseColumns._ID)) {
        queryColumns.add(BaseColumns._ID);
    }//from w  w  w  .j a  v a 2s  .  c om

    Cursor dbCursor;

    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        dbCursor = getContext().getContentResolver().query(contentUri,
                queryColumns.toArray(new String[queryColumns.size()]), selection, null, sortOrder);
    } else {
        dbCursor = new MatrixCursor(queryColumns.toArray(new String[queryColumns.size()]));
    }

    if (staticCursor != null) {
        Cursor[] cursors = new Cursor[] { staticCursor, dbCursor };
        cursor = new MergeCursor(cursors);
    } else {
        cursor = dbCursor;
    }
    manageCursor(cursor);

    this.contentUri = contentUri;

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), rowResId, cursor, displayColumns,
            resIDs, 1);
    // Use a custom binder to highlight the selected element.
    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (view.getVisibility() == View.VISIBLE && view instanceof TextView) {
                TextView text = (TextView) view;
                if (isItemChecked(cursor.getPosition())) {
                    text.setTypeface(Typeface.DEFAULT_BOLD);
                } else {
                    text.setTypeface(Typeface.DEFAULT);
                }
            }
            // Let the default binder do the real work.
            return false;
        }
    });
    setAdapter(adapter);
    setOnItemClickListener(this);
}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

private void displayCursor(Cursor tracksCursor) {
    SectionedListAdapter sectionedAdapter = new SectionedListAdapter(this);

    String[] fromColumns = new String[] { Tracks.NAME, Tracks.CREATION_TIME, Tracks._ID };
    int[] toItems = new int[] { R.id.listitem_name, R.id.listitem_from, R.id.bcSyncedCheckBox };
    SimpleCursorAdapter trackAdapter = new SimpleCursorAdapter(this, R.layout.trackitem, tracksCursor,
            fromColumns, toItems);/*  w  ww.j a va2 s  .  co  m*/
    sectionedAdapter.addSection("", trackAdapter);

    // Enrich the track adapter with Breadcrumbs adapter data
    trackAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
            if (columnIndex == 0) {
                final long trackId = cursor.getLong(0);
                final String trackName = cursor.getString(1);
                // Show the check if Breadcrumbs is online
                final CheckBox checkbox = (CheckBox) view;
                final ProgressBar progressbar = (ProgressBar) ((View) view.getParent())
                        .findViewById(R.id.bcExportProgress);
                checkbox.setVisibility(View.INVISIBLE);
                checkbox.setOnCheckedChangeListener(null);

                return true;
            }
            return false;
        }
    });

    setListAdapter(sectionedAdapter);
}

From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java

@AfterViews
void setupIssuesGrid() {
    gridView.setEmptyView(emptyGridView);
    gridView.setOnItemClickListener(new IssuesGridOnItemClickListener());

    final SimpleCursorAdapter issueListAdapter = new SimpleCursorAdapter(this, R.layout.include_issue, null,
            new String[] { DownloadManager.COLUMN_DESCRIPTION, DownloadManager.COLUMN_STATUS },
            new int[] { R.id.dateTextView, R.id.stateTextView }, 0) {

        @Override/*from  w w  w . j a v a  2  s.co  m*/
        public View getView(final int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            View deleteButton = view.findViewById(R.id.issueDeleteButton);
            deleteButton.setOnClickListener(new IssueDeleteButtonOnClickListener(position));

            // Load the thumbnail image
            ImageView image = (ImageView) view.findViewById(R.id.issueImageView);
            Uri uri = Uri.parse(getCursor().getString(getCursor().getColumnIndex(DownloadManager.COLUMN_URI)));
            Picasso.with(image.getContext()).load(IssueDownloadService_.getThumbnailUriForPDFUri(uri))
                    .placeholder(R.drawable.issue_placeholder).into(image);
            return view;
        }
    };
    issueListAdapter.setViewBinder(new IssuesGridViewBinder(this));
    gridView.setAdapter(issueListAdapter);

    getLoaderManager().initLoader(1, null, new IssuesGridLoaderCallbacks(this, issueListAdapter));
}

From source file:com.piusvelte.sonet.core.SonetNotifications.java

private void loadNotifications() {
    Cursor c = this.managedQuery(Notifications.getContentUri(SonetNotifications.this),
            new String[] { Notifications._ID, Notifications.CLEARED, Notifications.NOTIFICATION },
            Notifications.CLEARED + "!=1", null, null);
    SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.notifications_row, c,
            new String[] { Notifications.CLEARED, Notifications.NOTIFICATION },
            new int[] { R.id.notification, R.id.notification });
    sca.setViewBinder(mViewBinder);
    setListAdapter(sca);// ww  w.j a v a 2  s  .  co  m
}

From source file:com.shafiq.myfeedle.core.MyfeedleNotifications.java

private void loadNotifications() {
    Cursor c = this.managedQuery(Notifications.getContentUri(MyfeedleNotifications.this),
            new String[] { Notifications._ID, Notifications.CLEARED, Notifications.NOTIFICATION },
            Notifications.CLEARED + "!=1", null, null);
    SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.notifications_row, c,
            new String[] { Notifications.CLEARED, Notifications.NOTIFICATION },
            new int[] { R.id.notification, R.id.notification });
    sca.setViewBinder(mViewBinder);
    setListAdapter(sca);/*w  ww  .  j av a2s  .com*/
}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

private void setupList(final HorizontialListView listview, final SimpleCursorAdapter listAdapter,
        final Cursor cursr) {
    if (cursr == null || cursr != null && cursr.getCount() == 0) {
        Toast.makeText(getApplication(), "No books available", Toast.LENGTH_LONG);
    } else {//from   w ww . j  av a2  s. c  o m
        listview.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(final ContextMenu conMenu, final View v,
                    final ContextMenuInfo menuInfo) {
                final LinearLayout ll = (LinearLayout) ((HorizontialListView) v)
                        .getChildAt(((AdapterContextMenuInfo) menuInfo).position);
                final Drawable bookCover = ((ImageView) ll.getChildAt(0)).getDrawable();
                final String bookTitle = ((TextView) ll.getChildAt(1)).getText().toString();
                conMenu.setHeaderIcon(bookCover); // set to book cover
                conMenu.setHeaderTitle(bookTitle); // set to book title
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_VIEW_DETAILS, 0,
                        R.string.book_grid_context_item_view_book_details);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_OPEN_BOOK, 1,
                        R.string.book_grid_context_item_open_book);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_DELETE_BOOK, 2,
                        R.string.book_grid_context_item_delete_book);
            }
        });
        listview.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> av, final View v, final int pos, final long id) {
                myApp.dataMdl.launchBook(EBookLauncherActivity.this, id);
            }

            @Override
            public void onNothingSelected(final AdapterView<?> arg0) {
            }
        });
        listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                boolean retval = false;
                final int idColIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
                final int thumbColIndex = cursor.getColumnIndexOrThrow(DeviceFactory.getCoverImgColumnName());

                if (columnIndex == idColIndex) {
                    try {
                        final ImageView coverImg = (ImageView) view;
                        final String thumbnailFilename = cursor.getString(thumbColIndex);
                        final Bitmap bitmap = myApp.dataMdl.getBookCoverImg(EBookLauncherActivity.this,
                                thumbnailFilename);
                        coverImg.setImageDrawable(new BitmapDrawable(bitmap));
                        retval = true;
                    } catch (final Exception e) {
                        Log.e(EBookLauncherApplication.LOG_TAG, EBookLauncherActivity.LOG_TAG + "Exception ",
                                e);
                    }
                    retval = true;
                }
                return retval;
            }
        });
        listview.setAdapter(listAdapter);
        registerForContextMenu(listview);
        startManagingCursor(cursr);
    }
}