开发者

Android : How to create new EditText onClickListener

开发者 https://www.devze.com 2023-03-24 07:28 出处:网络
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?

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

精彩评论

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