英文:
Spinner First Item Devider android
问题
我在我的Android应用程序中使用了类似下面的Spinner:
spino = dialog.findViewById(R.id.language_spinner);
if (spino != null) {
spino.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item_position = String.valueOf(position);
int itemposition = Integer.parseInt(item_position);
String SelectedLang = String.valueOf(spino.getAdapter().getItem(position));
viewModel.SelectedLangPosition = itemposition;
switch (SelectedLang) {
case "English":
viewModel.SelectedLang = "en";
break;
case "ગુજરાતી":
viewModel.SelectedLang = "gu";
break;
case "हिंदी":
viewModel.SelectedLang = "hi";
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
它按预期工作,但我想为我的第一个标题项"choose video lanaguage"添加视图分隔符,我不知道该如何实现。我的Spinner当前的外观如下:
谢谢!
英文:
I am using spinner in my android application like below
spino = dialog.findViewById(R.id.language_spinner);
if (spino != null) {
spino.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item_position = String.valueOf(position);
int itemposition = Integer.parseInt(item_position);
String SelectedLang = String.valueOf(spino.getAdapter().getItem(position));
viewModel.SelectedLangPosition = itemposition;
switch (SelectedLang) {
case "English":
viewModel.SelectedLang = "en";
break;
case "ગુજરાતી":
viewModel.SelectedLang = "gu";
break;
case "हिंदी":
viewModel.SelectedLang = "hi";
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Its working fine as expected, but I am looking for make view divider for my first title item called choose video lanaguage, I am not getting idea how I can do it. my current look of spinner is like below
Thanks
答案1
得分: 0
第一种方法是将以下两行代码添加到您的Spinner XML 中:
android:spinnerMode="dialog"
android:prompt="@string/promptMsg"
其中 "promptMsg" 被设置为 "选择语言"。或者您可以在代码中以编程方式设置标题消息:
保持 spinnerMode 设置为 dialog,并在您的 Java 代码中添加以下内容:
spinner.setPrompt("选择语言");
英文:
Two ways you can do this.
The first way is to add these two lines of code to your Spinner XML:
android:spinnerMode="dialog"
android:prompt="@string/promptMsg"
promtMsg being "Select Language". Or you can set your title message programmatically:
Keep spinnerMode set to dialog and add this to your java code
spinner.setPrompt( "Select language");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论