我正在使用此示例代码来填充 Spinner。从数据库中读取数据。选择显示正确 - 在这种情况下,它显示“绿色”和“红色”。
Spinner spinnerColor = (Spinner) findViewById(R.id.spinnertProfile);
mProfileDbHelper = new ProfileDbAdapter(this);
mProfileDbHelper.open();
Cursor profilesCursor = mProfileDbHelper.fetchAllProfiles();
startManagingCursor(profilesCursor);
// Create an array to specify the fields we want to display in the list
String[] from = new String[] { ProfileDbAdapter.COL_PROFILE_TITLE };
// and an array of the fields we want to bind those fields to
int[] to = new int[] { R.id.textviewColors };
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter profilesAdapter = new SimpleCursorAdapter(this,
R.layout.profile_color, profilesCursor, from,
to);
spinnerColor.setAdapter(profilesAdapter);
}
但是,当我更改为使用不同的布局时android.R.layout.simple_spinner_dropdown_item。微调器文本消失了。
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter profilesAdapter = new SimpleCursorAdapter(this,
R.layout.profile_color, profilesCursor, from,
to);
profilesAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerColor.setAdapter(profilesAdapter);
请参阅下面不带和带simple_spinner_dropdown_item的快照:
有什么我可能会错过的吗?