喜 我正在尝试动态创建多行文字。
RelativeLayout rel = (RelativeLayout) findViewById(R.id.layout_info);
EditText tt = new EditText(getContext());
tt.setId(100);
RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.FILL_PARENT);
rp.addRule(RelativeLayout.BELOW, R.id.lbl_infotitle);
rp.width = 0;
tt.setTextColor(Color.BLACK);
tt.setBackgroundColor(android.R.color.transparent);
tt.setMaxLines(5);
tt.setSingleLine(false);
tt.setGravity(Gravity.LEFT);
tt.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
tt.setText("This section helps to maintain the"
+ "Personal Profile of subscriber."
+ "Screen contains the link" + " to sub sections such as,");
tt.setLayoutParams(rp);
rel.addView(tt, new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
但我的edittext始终只是单行。 (不能获得包装效果)
如果有人提供解决方案,那就太棒了。它可能是多余的,但我提到了所有解决方案,没有任何动态。请帮助我实现这一目标。
答案 0 :(得分:0)
添加到yout编辑文本textChangeListener并在重写方法中执行所需的操作。
例如
edit.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});