gpt4 book ai didi

android - 在android中获取所选微调器的文本

转载 作者:行者123 更新时间:2023-12-04 09:16:02 25 4
gpt4 key购买 nike

我在我的 android 应用程序中使用微调器,如下所示

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 selected = spino.getSelectedView().toString();
Log.e("selected position",""+itemposition);
Log.e("selected Text",selected);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}
else{
Log.e("Selected item :","NULL:");
}
xml布局如下
 <Spinner
android:id="@+id/language_spinner"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:fontFamily="@font/popins_reguler"
android:entries="@array/languages"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:theme="@style/Spinner"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp">
获取所选位置的位置工作正常,但是我正在获取所选位置的文本如下
androidx.appcompat.widget.AppCompatTextView{dc81ebe V.ED..... ........ 0,35-986,111 #1020014 android:id/text1}
任何人都可以帮我获取微调器选定位置的文本吗?
谢谢!

最佳答案

要获取所选项目的文本,请使用 spinner.getAdapter().getItem(position)

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 selected = String.valueOf(spino.getAdapter().getItem(position));
Log.e("selected position",""+itemposition);
Log.e("selected Text",selected);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}
else{
Log.e("Selected item :","NULL:");
}

关于android - 在android中获取所选微调器的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63211653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com