【发布时间】:2015-01-18 23:17:04
【问题描述】:
我使用了一个稍微修改过的 NumberPicker,当活动开始时,默认值已经被选中。这很烦人,因为它会调出键盘或调出对话框来剪切/复制/粘贴。我确实指示键盘保持向下,但它仍然被选中,并且会弹出剪切/复制/粘贴对话框。一旦我滚动浏览这些值,该数字就不再被选中并且它正常运行。有谁知道如何将 NumberPicker 设置为在启动时不选择任何内容?
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class NumPicker extends NumberPicker
{
public NumPicker(Context context)
{
super(context);
}
public NumPicker(Context context, AttributeSet attrs)
{
super(context, attrs);
processAttributeSet(attrs);
}
public NumPicker(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
processAttributeSet(attrs);
}
/**
* Reads the xml, sets the properties
*/
private void processAttributeSet(AttributeSet attrs)
{
setMinValue(attrs.getAttributeIntValue(null, "min", 0));
setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
setValue(4);
}
}
这是它在xml中的使用方式:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="40dp"
style="@style/CustomText"
max="100"
min="2"
【问题讨论】:
标签: android numberpicker