Java android中的默认微调器样式
我正在开发一个android应用程序,其中使用simpleAdaptor从数据库填充一个微调器Java android中的默认微调器样式,java,android,sqlite,android-layout,android-widget,Java,Android,Sqlite,Android Layout,Android Widget,我正在开发一个android应用程序,其中使用simpleAdaptor从数据库填充一个微调器 SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,R.layout.dbspinner, depcur, from, to); dep.setAdapter(deptype); 数据加载很好,但我不喜欢微调器的“外观” 我用的旋转器 ArrayAdapter<CharSequence> practype = Arra
SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,R.layout.dbspinner, depcur, from, to); dep.setAdapter(deptype);
数据加载很好,但我不喜欢微调器的“外观”
我用的旋转器
ArrayAdapter<CharSequence> practype = ArrayAdapter.createFromResource(this,R.array.practice, android.R.layout.simple_spinner_item);
ArrayAdapter practype=ArrayAdapter.createFromResource(这个,R.array.practice,android.R.layout.simple\u微调器项目);
更漂亮的是旁边有一个单选按钮,而我得到的那个只是用线条分隔的内容,一点也不漂亮
我尝试在我的dbspinner布局中进行各种更改,但没有什么能与android中的默认股票微调器相比。我还尝试用android.R.layout.simple\u spinner\u项目替换dbspinner,但我得到了带有单选按钮但没有文本的空白框
如何获取股票默认微调器
我应该将数据库的内容加载到一个字符串中,并提交给数组适配器吗?如果是这样的话,如何使用它?您可以使用以下代码:
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Category");
builder.setCancelable(true);
builder.setSingleChoiceItems(CATEGORIES_TXT, mSelectedCategory, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//new category selected
dialog.dismiss();
}
});
AlertDialog alert=builder.create();
alert.show();
CATEGORIES\u TXT
是一个字符串[],而mSelectedCategory
是一个int
表示所选类别。简单微调器项定义为:
<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" />
无用:(仍然显示中间有一行的小框:(.如何将数据库列加载到字符串中?如果我可以这样做,我可以直接使用array adapterIt works-我正在使用它。请确保您的数据库已实际填充并且使用了正确的列名。它在android:id=“@android:id/text1”附近给出了一个错误.我创建了一个xml文件,删除了所有内容并粘贴了此文件。是否正确?错误是找不到与给定名称匹配的资源(在'id'处,值为'@android:id/tvspin'))您需要更好地理解ID和包。不要使用不同的XML布局,请使用简单的\u微调器\u项并使用我提供的代码。它假定TextView资源ID为“android.R.ID.text1”。
// 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);