我正在开发一个 android 应用程序,我在其中使用 simpleAdaptor 从数据库中填充一个微调器。
SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,R.layout.dbspinner, depcur, from, to); dep.setAdapter(deptype);
数据加载正常,但我不喜欢 Spinner 的“外观”。
我得到的微调器
ArrayAdapter<CharSequence> practype = ArrayAdapter.createFromResource(this,R.array.practice, android.R.layout.simple_spinner_item);
旁边有一个单选按钮更漂亮,而我得到的只是显示用线分隔的内容,一点也不漂亮。
我尝试了对 dbspinner 布局的各种更改,但没有什么能与 android 中的默认库存微调器相等。我还尝试用 android.R.layout.simple_spinner_item 替换 dbspinner,但我得到了带有单选按钮但没有文本的空白框。
如何获得库存默认微调器?
我应该将数据库的内容加载到一个字符串中并提供给数组适配器吗?如果是怎么办?
最佳答案
simple_spinner_item 定义为:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee" />
因此,要将它用作项目的 View ,请使用“text1”作为资源整数数组中的 ID。
即:
// Create the array containing column names
String[] columns = new String[] { "ColumnNameX" };
// Create the array containing resource ids
int[] resources = new int[] { android.R.id.text1 };
// Create the cursor adapter
mCursorAdapter = new SimpleCursorAdapter(
MyActivity.this,
android.R.layout.simple_spinner_item,
data,
columns,
resources);
关于java - android中的默认微调器样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6957449/