带有textSize变量的自定义NumberPicker

时间:2015-08-04 08:42:24

标签: android

我正在尝试创建自己的numberPicker,因为我看到了here,但我无法使用变量来设置textSize。
任何人都可以猜到为什么不起作用?

{ 'get':    {method:'GET'},
  'save':   {method:'POST'},
  'query':  {method:'GET', isArray:true},
  'remove': {method:'DELETE'},
  'delete': {method:'DELETE'} };


如果我替换此行

public class MyNumberPicker extends NumberPicker {

    float myTextSize = 35.0f;

    public MyNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        updateView(child);
    }

    @Override
    public void addView(View child, int index,
            android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    private void updateView(View view) {
        if (view instanceof EditText) {
            ((EditText) view).setTextSize(myTextSize);
            ((EditText) view).setTextColor(Color.BLACK);
        }
    }

    public void setTextSize(int _textSize) {
        myTextSize = _textSize;
    }
}

用这个

((EditText) view).setTextSize(myTextSize);

有效,但后来我无法更改textSize;

更新
经过一些测试后,我发现在((EditText) view).setTextSize(35); 之后调用了addViews,但在setTextSize运行时,updateView的值仍为零。

0 个答案:

没有答案