【发布时间】:2020-08-02 01:56:00
【问题描述】:
我在我的 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)
标签: android android-arrayadapter android-spinner