当前位置: 首页>>代码示例>>Java>>正文


Java Spinner.setTag方法代码示例

本文整理汇总了Java中android.widget.Spinner.setTag方法的典型用法代码示例。如果您正苦于以下问题:Java Spinner.setTag方法的具体用法?Java Spinner.setTag怎么用?Java Spinner.setTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.Spinner的用法示例。

在下文中一共展示了Spinner.setTag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initSpinner

import android.widget.Spinner; //导入方法依赖的package包/类
public static void initSpinner(DBAdapter dbAdapter, View pSpinner,
                               String tableName, String selection, long selectedId, boolean addEmptyValue) {
    try {
        Spinner spnCurrentSpinner = (Spinner) pSpinner;
        spnCurrentSpinner.setTag(ConstantValues.IS_INITIALIZATION_IN_PROGRESS_TAG);

        Cursor dbcRecordCursor;
        //@formatter:off
        if (addEmptyValue) {
            String selectSql =
                    "SELECT " +
                            "-1 AS " + DBAdapter.COL_NAME_GEN_ROWID + ", " +
                            "' ' AS " + DBAdapter.COL_NAME_GEN_NAME +
                    " UNION " +
                    " SELECT " +
                            DBAdapter.COL_NAME_GEN_ROWID +
                            ", " + DBAdapter.COL_NAME_GEN_NAME +
                    " FROM " + tableName +
                    " WHERE 1 = 1 ";
            if (selection != null && selection.length() > 0) {
                selectSql = selectSql + selection;
            }
            selectSql = selectSql + " ORDER BY " + DBAdapter.COL_NAME_GEN_NAME;

            dbcRecordCursor = dbAdapter.execSelectSql(selectSql, null);
        }
        else {
            dbcRecordCursor = dbAdapter.query(tableName, DBAdapter.COL_LIST_GEN_ROWID_NAME, "1 = 1 " + selection, null, DBAdapter.COL_NAME_GEN_NAME);
        }
        //@formatter:on

        if (dbcRecordCursor == null)
            return;

        List<String> recordsList = new ArrayList<>();
        while (dbcRecordCursor.moveToNext()) {
            recordsList.add(dbcRecordCursor.getString(1));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<>(pSpinner.getContext(), R.layout.ui_element_spinner_item, recordsList);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnCurrentSpinner.setAdapter(adapter);

        if (selectedId >= 0) {
            //set the spinner to this id
            dbcRecordCursor.moveToFirst();
            for (int i = 0; i < dbcRecordCursor.getCount(); i++) {
                if (dbcRecordCursor.getLong(DBAdapter.COL_POS_GEN_ROWID) == selectedId) {
                    spnCurrentSpinner.setSelection(i);
                    break;
                }
                dbcRecordCursor.moveToNext();
            }
        }
        dbcRecordCursor.close();
    }
    catch (Exception e) {
        Utils.showReportableErrorDialog(pSpinner.getContext(), AndiCar.getAppResources().getString(R.string.error_sorry), e.getMessage(), e);
    }
}
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:60,代码来源:Utils.java



注:本文中的android.widget.Spinner.setTag方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。