开发者

Android : How to create new EditText onClickListener

I am new here, sorry if I am not so good in the explainаtion. ;) I want to add and remove a dynamic EditText fields?

 private final View.OnClickListener addRowListener = new View.OnClickListener() {
      @Override
      public void onClick(View view) {
           //HERE????
      };

Than开发者_运维知识库k you in advance


If you want to create the views

 @Override
 public void onClick(View view) {
      TextView text = new TextView(yourActivity.this);
 };

If you have the views

 TextView TV1,TV2;
 @Override
 public void onClick(View view) {
      if(TV1.getVisibility()==View.GONE)
           TV1.setVisibility(View.VISIBLE);
      else
           TV1.setVisibility(View.GONE);
 };


you have to add and remove your EditText from the Layout dynamically.

LinearLayout layout=(LinearLayout)findViewById(R.id.layout);

To create New

EditText text=new EditText(this); layout.addView(text);

to Remove

layout.removeView(text);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜