1

Originally the number picker worked perfectly, but as soon as I put it in a listview item I was unable to enter numbers. When you select it to edit the text it sometimes brings up a text keyboard and sometimes a number keyboard. When pressing the numbers you can see it registering the letter keyboard is being pressed behind it.

Could this possibly be an issue with having a number picker in a listview item?

I've tried changing several attributes regarding focus and changing the input type of the edit text itself (which is indeed set to number correctly by default) and had no luck.

Number picker list item xml:

<?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/timePicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="32dp" />
    <TextView
        android:id="@+id/minutesText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_toEndOf="@+id/timePicker"
        android:layout_centerVertical="true"
        android:text="@string/test"
        android:textColor="@android:color/white"
        android:textSize="14sp" />
</RelativeLayout>

Then using this in the adapter for the listview to get the number picker item:

private View getNumberPickerView(int position, View convertView, ViewGroup parent) {
        NumberPickerViewHolder holder;

        if (convertView == null) {
            convertView = mInflator.inflate(R.layout.number_picker_list_item, parent,false);

            holder = new NumberPickerViewHolder();
            holder.numberPicker = (NumberPicker) convertView.findViewById(R.id.timePicker);
            holder.minutesText = (TextView) convertView.findViewById(R.id.minutesText);
            convertView.setTag(holder);
        }

        else {
            holder = (NumberPickerViewHolder) convertView.getTag();
        }

        if (position == mNumberPickerPos) {
            holder.numberPicker.setMinValue(0);
            holder.numberPicker.setMaxValue(300);

            holder.minutesText.setText(R.string.test);
        }
    return convertView;
}

NumberPickerViewHolder is just an inner class that is used to reuse the listview items.

Edit: I also have an onValueChange listener for the number picker. I didn't think that would be causing the issue, but I checked anyway. Problem still happens with it removed.

MikeIV
  • 31
  • 6

1 Answers1

0

Seems that nobody has an answer for this. What I ended up doing was taking the NumberPicker out of the ListView item and replacing it with an EditText that opened up a dialog box with the NumberPicker in it. It works perfectly since it is no longer part of the ListView item

MikeIV
  • 31
  • 6