如何查看微调器上的值?
我的问题是:我在我的 Android 应用程序上使用 spinner。但是,我根本看不到微调器上显示的默认值。我可以选择元素,但在微调器上看不到任何文本。似乎该值被隐藏并且不显示任何内容,仅显示微调器本身和下拉箭头。
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();
}
}
}
My question is: I am using spinner on my android app. However, I can't see the default value shown on the spinner, at all. I can select elements but I can't see any text on the spinner. It seems like the value is hidden and doesn't show anything, just the spinner itself and drop down arrow.
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以调用 spinner.setSelection 来设置当前状态
旋转到任何你想要的。这绝对有效
,但你还必须打电话
setDropDownViewResource()
比如说
You can call spinner.setSelection to set the current state of the
spinner to whatever you want. And that definitely works
but you must also call
setDropDownViewResource()
let say