java - android中的默认微调器样式

标签 java android sqlite android-layout android-widget

我正在开发一个 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/

相关文章:

php - Android 可以下载任何类型的日历事件吗?如果是这样,文件结构是什么?

Android:AsyncTask 的优先级高于 Service

Android:你能通过电话发送/接收数据吗?

android - 如何显示数据库中的古吉拉特语文本

sqlite - Xamarin SQLite 查询

java - 公共(public)类的父类(super class)可以是包私有(private)的吗?

java - Android 谷歌地图 V2 用户定位

c# - 使用 SQLite 测试 ASP Net Core 应用程序抛出未知函数 : newid()

java - CSV 文件在 Java 中无法正确写入

java - 小程序代码问题