我想要一个始终显示在 Spinner 中的固定值,当单击 Spinner 时,该值不应列在下拉选择中。到现在为止我有以下
Definition XML:
<Spinner
android:layout_width="76dp"
android:layout_height="40dp"
android:id="@+id/right_shift"
android:layout_row="0"
android:layout_column="0"/>
Java:
final Spinner right = (Spinner) findViewById(R.id.right_shift)
ArrayList<String> rightShift = new ArrayList<String>();
rightShift.add(" >>"); //THIS SHOULD BE THE VALUE THAT IS ALWAYS DISPLAYED
for (int i=0; i<5; i++)
...//add other values to arraylist
...//set values of arraylist to spinner
right.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
right.setSelection(0);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
但是,当单击 Spinner 时,预选项目将再次显示在下拉列表中,并且right.setselection(0)
执行速度不够快,所以我仍然会在大约 0.5 秒内看到所选项目...是否有其他/更简单的方法来执行此操作?