#2
tlliqi2014-03-13 20:21
|
下面是我实现自定义控件代码:
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));
}
});
}
}
问题来了,如何在别的页面加载这个控件后改变文本框里面的初始值;