-1

Hi please lead me some examples which demonstrate how to create editText with "delete" button , when click on the delete option it will remove the created editText . Thanks in advance ...

code for creating textEdit dynamically..

LinearLayout rAlign = (LinearLayout)findViewById(R.id.lId);
        EditText newPass = new EditText(getApplicationContext());
        allEds.add(newPass);
        newPass.setHint("Name of Label");
        newPass.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        newPass.setWidth(318);
        newPass.setTextColor(Color.parseColor("#333333"));
        newPass.setId(MY_BUTTON);
        //newPass.
        //newPass.setOnClickListener(this);
        rAlign.addView(newPass);
        MY_BUTTON ++;               
        addSpinner();  //Function for adding spinner 
user1682133
  • 193
  • 2
  • 4
  • 13

1 Answers1

1

The layout could be something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="50dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_toRightOf="@+id/editText1"
    android:text="Button" />

And the Java could be like this:

public class MainActivity extends Activity implements OnClickListener {

TextView tv;
Button btn;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button) findViewById(R.id.button1);
    tv = (TextView) findViewById(R.id.editText1);

    btn.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    tv.setVisibility(View.GONE);

}

}

Gafanha
  • 101
  • 6
  • To clarify, do you want to dynamically add the textview and button one at a time or do you want to inflate an xml layout that contains a textview and a button? – Gafanha Sep 29 '12 at 18:26