如何查看微调器上的值?

发布于 2024-12-04 12:28:24 字数 1739 浏览 1 评论 0原文

我的问题是:我在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2024-12-11 12:28:24

您可以调用 spinner.setSelection 来设置当前状态
旋转到任何你想要的。这绝对有效

spinner.setSelection(0);

,但你还必须打电话
setDropDownViewResource()

比如说

adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);

You can call spinner.setSelection to set the current state of the
spinner to whatever you want. And that definitely works

spinner.setSelection(0);

but you must also call
setDropDownViewResource()

let say

adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文