【发布时间】:2015-07-02 04:27:24
【问题描述】:
EBelow 是我将 EditText 添加到我的布局的代码,它工作正常,但我希望它在创建的那些下方创建新的 EditText 框。如果您在代码中看到我应该更改或改进的内容,请发表评论。提前致谢。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_weight_log);
relativeLayout = (RelativeLayout)findViewById(R.id.relativeLayout);
tt= (EditText)findViewById(R.id.tt);
dd = (EditText)findViewById(R.id.dd);
aa = (Button) findViewById(R.id.add);
aa.setOnClickListener(new Button.OnClickListener()
{public void onClick
(View v) { aa();}});
}
public void aa()
{ for(i = 0; i <100; ++i);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.BELOW);
params.setMargins(0,600,0,0);
EditText edtTxt = new EditText(this);
int maxLength = 5;
edtTxt.setHint("editText1");
edtTxt.setLayoutParams(params);
edtTxt.setBackgroundColor(Color.WHITE);
edtTxt.setInputType(InputType.TYPE_CLASS_DATETIME);
edtTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
edtTxt.setFilters(fArray);
layout.addView(edtTxt);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params1.setMargins(0,600,0,0);
EditText editText = new EditText(this);
int maxLength1 = 4;
editText.setHint("editText2");
editText.setLayoutParams(params1);
editText.setBackgroundColor(Color.WHITE);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
fArray[0] = new InputFilter.LengthFilter(maxLength1);
editText.setFilters(fArray);
layout.addView(editText);
}
【问题讨论】:
-
在 onCreate 方法中检查 'aa'
-
这是我复制代码时犯的一个错误,我现在进行了更正。我仍然无法在创建的编辑文本下方获取新的编辑文本。
标签: javascript android android-activity android-studio android-edittext