android.widget.SimpleCursorAdapter#setViewBinder ( )源码实例Demo

下面列出了android.widget.SimpleCursorAdapter#setViewBinder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SmsScheduler   文件: SmsListActivity.java
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;
}
 
源代码2 项目: sana.mobile   文件: NotificationList.java
/**
 * {@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);
}
 
源代码3 项目: Yamba   文件: TimelineFragment.java
@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);
}
 
源代码4 项目: moVirt   文件: VmSnapshotsFragment.java
@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;
}
 
源代码5 项目: moVirt   文件: VmDisksFragment.java
@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;
}
 
源代码6 项目: moVirt   文件: StorageDomainFragment.java
@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;
}
 
源代码7 项目: moVirt   文件: SnapshotDisksFragment.java
@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;
}
 
源代码8 项目: sniffer154   文件: SessionManagerActivity.java
@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);
}
 
源代码9 项目: codeexamples-android   文件: List3.java
@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);
}