注册 登录
编程论坛 Android开发

关于自定义EditText,求助!

绝爱小朱 发布于 2014-03-13 16:50, 3220 次点击
下面是我实现自定义控件代码:
public class MyEditText extends LinearLayout {
    private EditText mEditText;
    private Button bAdd;
    private Button bReduce;

    public MyEditText(final Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    protected void onFinishInflate() {
        super.onFinishInflate();

        LayoutInflater.from(getContext()).inflate(R.layout.myedittext, this);
        init_widget();
        addListener();

    }

    public void init_widget() {

        mEditText = (EditText) findViewById(R.id.et01);
        bAdd = (Button) findViewById(R.id.bt01);
        bReduce = (Button) findViewById(R.id.bt02);
        mEditText.setText("1");
    }

    public void addListener() {
        bAdd.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                int num = Integer.valueOf(mEditText.getText().toString());
                num++;
                mEditText.setText(Integer.toString(num));
            }
        });

        bReduce.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                int num = Integer.valueOf(mEditText.getText().toString());
                num--;
                mEditText.setText(Integer.toString(num));
            }
        });
    }

}
问题来了,如何在别的页面加载这个控件后改变文本框里面的初始值;
1 回复
#2
tlliqi2014-03-13 20:21
路过
1