本文整理汇总了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);
}
}