开发者

creating wrapping effect in edittext dynamically

hi I am trying to create a multiline editext dynamically.

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."  
  开发者_StackOverflow中文版                  + "Screen contains the link" + " to sub sections such as,");  
tt.setLayoutParams(rp);  
rel.addView(tt, new RelativeLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

But my edittext is always singleline only. (can't obtain wrapping effect)

It would be great if anyone provide a solution. It may be redundant, but i referred all the solutions, nothing works dynamically. Please help me to achieve this.


Add to yout edit text textChangeListener and make needed actions in overriden methods.

For example

        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) {

        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜