0

I am trying to learn android development in Eclipse and I am stuck. I created a button with using this.

<Button
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:text="bla"
    android:layout_gravity="center"
    android:textSize="15dp"
     android:id="@+id/bla"
    />

And my listener is the following.

button1=(Button) findViewById(R.id.bla);
button1.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {

                    }
                });

What I want is the following. When I click my button I want 3 different textfields to be seen. After I enter some values to that textfields, I want to get back to the initial screen which contains button1. How can I do that? Also with which method I can store the values that are written to this textfields?

Edit:All answers were helpful and I upvoted them but I accepted Diego's answer because of the clarity

3 Answers 3

2

If you want the EditText appear after you click a Button you can include all of them in the same XML layout file, set the EditText to INVISIBLE (android:visibility="invisible") and change it to VISIBLE in the OnClick listener.

2

To create EditText call this on OnButton Click

LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout2);
EditText tv;
List<EditText> allEds = new ArrayList<EditText>();
for (int i = 0; i < 5; i++) {
    tv = new EditText(this);
    tv.setText("Dynamic TextView" + i);
    tv.setId(i + 5);
    ll.addView(tv);
}

And get inserted values from EditText check this

String[] strings = new String[allEds.size()];

for (int i = 0; i < allEds.size(); i++) {
    strings[i] = allEds.get(i).getText().toString();
}
2

Initially create 3 edit text's in your xml file and place them as invisible like android:visibility="invisible" for each and every edit text, now in our java file when button is clicked visible them. like buttonid.setVisibility(View.VISIBLE);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.