Java Code Examples for android.widget.SimpleCursorAdapter#setViewBinder()

The following examples show how to use android.widget.SimpleCursorAdapter#setViewBinder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmsListActivity.java    From SmsScheduler with GNU General Public License v2.0 7 votes vote down vote up
private SimpleCursorAdapter getSmsListAdapter() {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            this,
            android.R.layout.simple_list_item_2,
            DbHelper.getDbHelper(this).getCursor(),
            new String[] { DbHelper.COLUMN_MESSAGE, DbHelper.COLUMN_RECIPIENT_NAME },
            new int[] { android.R.id.text1, android.R.id.text2 }
    );
    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;
            if (textView.getId() == android.R.id.text2) {
                textView.setText(getFormattedSmsInfo(cursor));
                return true;
            }
            return false;
        }
    });
    return adapter;
}
 
Example 2
Source File: NotificationList.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Uri uri = getIntent().getData();
    if (uri == null) {
        uri = Notifications.CONTENT_URI;
    }

    Cursor cursor = managedQuery(uri, PROJECTION,
            Notifications.Contract.DOWNLOADED + "=1", null,
            Notifications.DEFAULT_SORT_ORDER);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            android.R.layout.two_line_list_item, cursor,
            new String[]{Notifications.Contract.PATIENT_ID,
                    Notifications.Contract.FULL_MESSAGE},
            new int[]{android.R.id.text1, android.R.id.text2});
    adapter.setViewBinder(this);
    setListAdapter(adapter);
}
 
Example 3
Source File: TimelineFragment.java    From Yamba with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
	super.onActivityCreated(savedInstanceState);

	mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item,
			null, FROM, TO, 0);
	mAdapter.setViewBinder(VIEW_BINDER);

	setListAdapter(mAdapter);

	getLoaderManager().initLoader(LOADER_ID, null, this);
}
 
Example 4
Source File: VmSnapshotsFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter snapshotListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.snapshot_list_item,
            null,
            new String[]{NAME, SNAPSHOT_STATUS, DATE, PERSIST_MEMORYSTATE},
            new int[]{R.id.snapshot_description, R.id.snapshot_status, R.id.snapshot_date, R.id.snapshot_persist_memorystate}, 0);
    snapshotListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(DATE)) {
                String date = DateUtils.convertDateToString(getActivity(), cursor.getLong(columnIndex));
                textView.setText(date);
            } else if (columnIndex == cursor.getColumnIndex(SNAPSHOT_STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.replace("_", " ").toUpperCase());
            } else if (columnIndex == cursor.getColumnIndex(PERSIST_MEMORYSTATE)) {
                textView.setText(getString(R.string.snapshot_memory));
                textView.setVisibility((new CursorHelper(cursor)).getBoolean(columnIndex) ? View.VISIBLE : View.GONE);
            }

            return true;
        }
    });

    return snapshotListAdapter;
}
 
Example 5
Source File: VmDisksFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter diskListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.disk_list_item,
            null,
            new String[]{NAME, SIZE, STATUS},
            new int[]{R.id.disk_name, R.id.disk_size, R.id.disk_status}, 0);
    diskListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(SIZE)) {
                long size = cursor.getLong(columnIndex);
                String sizeText = (size == -1) ? getString(R.string.disk_unknown_size) : new MemorySize(size).toString();
                textView.setText(sizeText);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.toUpperCase());
            }

            return true;
        }
    });

    return diskListAdapter;
}
 
Example 6
Source File: StorageDomainFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter storageDomainListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.storage_domain_list_item,
            null,
            new String[]{NAME, STATUS},
            new int[]{R.id.storage_domain_name, R.id.storage_domain_status}, 0);

    storageDomainListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == cursor.getColumnIndex(NAME)) {
                TextView textView = (TextView) view;
                String name = cursor.getString(cursor.getColumnIndex(NAME));
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                ImageView imageView = (ImageView) view;
                String statusString = cursor.getString(cursor.getColumnIndex(STATUS));
                imageView.setImageResource(StorageDomainStatus.fromString(statusString).getResource());
            }

            return true;
        }
    });

    return storageDomainListAdapter;
}
 
Example 7
Source File: SnapshotDisksFragment.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
protected CursorAdapter createCursorAdapter() {
    SimpleCursorAdapter diskListAdapter = new SimpleCursorAdapter(getActivity(),
            R.layout.disk_list_item,
            null,
            new String[]{NAME, SIZE, STATUS},
            new int[]{R.id.disk_name, R.id.disk_size, R.id.disk_status}, 0);
    diskListAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;

            if (columnIndex == cursor.getColumnIndex(NAME)) {
                String name = cursor.getString(columnIndex);
                textView.setText(name);
            } else if (columnIndex == cursor.getColumnIndex(SIZE)) {
                long size = cursor.getLong(columnIndex);
                String sizeText = (size == -1) ? getString(R.string.disk_unknown_size) : new MemorySize(size).toString();
                textView.setText(sizeText);
            } else if (columnIndex == cursor.getColumnIndex(STATUS)) {
                String status = cursor.getString(columnIndex);
                textView.setText(status == null ? getString(R.string.NA) : status.toUpperCase());
            }

            return true;
        }
    });

    return diskListAdapter;
}
 
Example 8
Source File: SessionManagerActivity.java    From sniffer154 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.session_manager_activity);
	mListViewSessions = (ListView) findViewById(R.id.listViewSessions);
	getLoaderManager().initLoader(0, null,
			new SessionLoaderCallbacks());
	mAdapter = new SimpleCursorAdapter(this, R.layout.session_list_row,
			null, FROM, TO, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
	mAdapter.setViewBinder(new SessionViewBinder());
	mListViewSessions.setAdapter(mAdapter);
	mListViewSessions
			.setOnItemClickListener(new SessionOnItemClickListener());
	registerForContextMenu(mListViewSessions);
}
 
Example 9
Source File: List3.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get a cursor with all phones
    Cursor c = getContentResolver().query(Phone.CONTENT_URI,
            PHONE_PROJECTION, null, null, null);
    startManagingCursor(c);

    // Map Cursor columns to views defined in simple_list_item_2.xml
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            android.R.layout.simple_list_item_2, c,
                    new String[] {
                        Phone.TYPE,
                        Phone.NUMBER
                    },
                    new int[] { android.R.id.text1, android.R.id.text2 });
    //Used to display a readable string for the phone type
    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            //Let the adapter handle the binding if the column is not TYPE
            if (columnIndex != COLUMN_TYPE) {
                return false;
            }
            int type = cursor.getInt(COLUMN_TYPE);
            String label = null;
            //Custom type? Then get the custom label
            if (type == Phone.TYPE_CUSTOM) {
                label = cursor.getString(COLUMN_LABEL);
            }
            //Get the readable string
            String text = (String) Phone.getTypeLabel(getResources(), type, label);
            //Set text
            ((TextView) view).setText(text);
            return true;
        }
    });
    setListAdapter(adapter);
}