0
 final LinearLayout ll=new LinearLayout(this);
 ll.setOrientation(LinearLayout.VERTICAL);
 scrl.addView(ll);
 Button add_btn=new Button(this);
 add_btn.setText("Click to add TextViiews and EditTexts");
 ll.addView(add_btn);
 add_btn.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 //String str;
TextView tv=(TextView)findViewById(R.id.tv1);    
 EditText et2=new EditText(getApplicationContext());
 String s=et2.getText().toString();
tv.setText(s);
 ll.addView(et2); 

I have created a button when i click on this button i will get edittext dynamically if i enter a value i should display the value I don't know how to display value and make use of it if suppose i want to add entered values in dynamically created edit text.

2
  • Your question isn't really clear. Try rephrasing. Commented Jan 11, 2013 at 14:14
  • I have created a button when i click on this button i will get edit text dynamically if i enter a value it should take the value into some variable it should display the value i have used textview to display but i am unable to get the values and display. Commented Jan 11, 2013 at 14:24

1 Answer 1

1

You cannot get text if you haven't added the view.Also you add textview on click of button. You can remove textview creation from onClick() and add it outside of it

EDIT(something like this):

   final LinearLayout ll=new LinearLayout(this);
   ll.setOrientation(LinearLayout.VERTICAL);
   scrl.addView(ll);
   Button add_btn=new Button(this);
   add_btn.setText("Click to add TextViiews and EditTexts");
   ll.addView(add_btn);
   add_btn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            String s=et2.getText().toString();
            tv.setText(s);
         }
    });
   TextView tv=(TextView)findViewById(R.id.tv1);    
   EditText et2=new EditText(getApplicationContext()); 
   ll.addView(et2); 
Sign up to request clarification or add additional context in comments.

4 Comments

i am getting force close when i click on button
01-11 19:56:33.455: E/AndroidRuntime(8089): at com.app.DynamicbuttonActivity$1.onClick(DynamicbuttonActivity.java:43)
01-11 19:56:33.455: E/AndroidRuntime(8089): at android.view.View$PerformClick.run(View.java:8816)
please paste your whole red logcat lines in your question and preferably your DynamicbuttonActivity.java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.