我想用一組顯示值創建NumberPicker。顯示NumberPicker時,值不應該改變,但最小值和最大值根據用戶操作動態更改。NumberPicker上的setMinValue未選擇正確的最小值
下面是代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<NumberPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
在主要活動
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] values = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
NumberPicker picker = (NumberPicker) findViewById(R.id.picker);
picker.setDisplayedValues(values);
picker.setMaxValue(7);
picker.setMinValue(3);
picker.setWrapSelectorWheel(false);
}
}
當我設定的最大而不設置了最小值,我用「0」之間的顯示值結束,並且「7」(包括在內)。如果我將minValue設置爲0,則具有相同的行爲。 但是,如果我將minValue設置爲3,則結束顯示「0」和「4」之間的值。當它應該在「3」和「7」之間時。
我不明白爲什麼。我做錯了什麼或者是否存在組件問題?
你能詳細解釋一下嗎?爲什麼它不能解決OP的問題?你不是也建議每當最小/最大值發生變化時顯示值應該改變(也許我誤解了)? – Bmuig
我的歉意,我誤解了你的建議。它按預期工作。對不起! –