我的问题是:我在我的Android应用程序上使用微调器。但是,我根本看不到微调器上显示的默认值。我可以选择元素,但我看不到微调器上的任何文本。看起来这个值是隐藏的并且没有显示任何内容,只有旋转器本身和下拉箭头。
mDbHelper = new DbAdapter(this);
mDbHelper.open();
cursor = mDbHelper.fetchAllBusinessCards();
startManagingCursor(cursor);
contactSpinner = (Spinner) findViewById(R.id.contactSpinner);
contactSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
fillData();
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "The planet is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
private void fillData() {
/*Create an array to specify the fields we want to display in the list (only the 'colourName' column in this case) */
String[] from = new String[]{DbAdapter.getKeyTitle() };
/* and an array of the fields we want to bind those fields to (in this case just the textView 'tvDBViewRow' from our new db_view_row.xml layout above) */
int[] to = new int[]{R.id.tvDBViewRow};
/* Now create a simple cursor adapter.. */
SimpleCursorAdapter colourAdapter =
new SimpleCursorAdapter(this,R.layout.db_view_row, cursor, from, to);
/* and assign it to our Spinner widget */
contactSpinner.setAdapter(colourAdapter);
//contactSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
contactSpinner.setSelection(0);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mDbHelper != null) {
mDbHelper.close();
}
}
}
答案 0 :(得分:1)
您可以调用spinner.setSelection来设置当前的状态 任何你想要的旋转器。这肯定有效
spinner.setSelection(0);
但你也必须打电话 setDropDownViewResource()
让我们说
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);