0
onFocusChange
не вызывается. Я создал новый проект только с этим, и он не работает. Вот код:NumberPicker: функция onFocusChange никогда не называлась
private NumberPicker np;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
np = (NumberPicker)findViewById(R.id.numberPicker1);
np.setMaxValue(99);
np.setMinValue(0);
np.setValue(50);
np.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Log.d(TAG, "np hasFocus " + hasFocus);
}
});
}
и XML:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
>
</NumberPicker>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="test button"
/>
</LinearLayout>
Можете ли вы помочь с тем, что происходит? Я использую андроид 4.4.2, API 19.
Я вижу, что есть a [onValueChangeListerner] (http://developer.android.com/intl/zh-tw/reference/android/widget/NumberPicker.OnValueChangeListener.html) –
@Uma Kanth Спасибо, но я действительно хотел, чтобы onFocusChange ... –