1
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="testEditText " type="id"/>
</resources>

final EditText testEditText = new EditText(getActivity());
testEditText.setId(R.id.testEditText);

I created a edittext dynamically but i cannot set text into it from another function.

EditText testEditText= (EditText) v.findViewById(R.id.testEditText);

i tried to initialize it but it always return null.

Is there any way i can set and get value of testedittext from different function

3
  • 1
    findViewById() is expensive, why not just keep a reference to the EditText and pass that along since you are dynamically creating it? Commented May 21, 2014 at 19:22
  • Just curious, have you added the view to your layout? Commented May 21, 2014 at 19:23
  • yea passing it would work but i dont want it pass just was looking to gettext without passing it Commented May 21, 2014 at 19:27

2 Answers 2

1

You can set any integer value in setId(). you have to set some unique values to differentiate with other dynamically created views.

so give like this.

testEditText.setId(1);

so you can use this id for onClickListner , onTouchListner etc...

Sign up to request clarification or add additional context in comments.

Comments

0

above oncrtae

EditText test;

in on create

test = (EditText) v.findViewById(R.id.testEditText);

test.setText("bla bla");

Comments

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.