java android中的默认微调样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6957449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Default spinner style in android
提问by 8A52
I am developing an android application in which I am populating a spinner from database using simpleAdaptor.
我正在开发一个 android 应用程序,其中我使用 simpleAdaptor 从数据库中填充一个微调器。
SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,R.layout.dbspinner, depcur, from, to); dep.setAdapter(deptype);
Data is loading fine but I don't like the "Look" of the Spinner.
数据加载正常,但我不喜欢 Spinner 的“外观”。
The spinner I got with
我得到的旋转器
ArrayAdapter<CharSequence> practype = ArrayAdapter.createFromResource(this,R.array.practice, android.R.layout.simple_spinner_item);
is more beautiful with a radio button on the side,while the one I got is just showing contents separated by lines which is not at all beautiful.
侧面有一个单选按钮更漂亮,而我得到的只是显示由线条分隔的内容,一点也不漂亮。
I tried various changes in my layout of dbspinner but nothing is equal to the default stock spinner in android. I also tried to replace dbspinner with android.R.layout.simple_spinner_item but I got blank boxes with radio buttons but no text.
我在 dbspinner 的布局中尝试了各种更改,但没有什么能与 android 中的默认股票微调器相同。我也尝试用 android.R.layout.simple_spinner_item 替换 dbspinner 但我得到了带有单选按钮但没有文本的空白框。
How can I get the stock default spinner?
如何获得股票默认微调器?
Should i load the contents of database into a string and give to array adapter? If so how to it?
我应该将数据库的内容加载到字符串中并提供给数组适配器吗?如果有怎么办?
采纳答案by Austin Hanson
The simple_spinner_item is defined as:
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" />
So to use it as your item's view, use "text1" as your id in the resource integer array.
因此,要将其用作项目的视图,请在资源整数数组中使用“text1”作为您的 id。
Ie:
IE:
// 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);
回答by Ovidiu Latcu
You can use this code:
您可以使用此代码:
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_TXT
is a String[] and mSelectedCategory
an int
representing the selected category.
CATEGORIES_TXT
是一个 String[] 和mSelectedCategory
一个int
代表所选类别。