嗨请告诉我一些示例,演示如何使用“删除”按钮创建editText,当单击删除选项时,它将删除创建的editText。提前谢谢......
动态创建textEdit的代码..
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
答案 0 :(得分:1)
布局可能是这样的:
<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" />
Java可能是这样的:
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);
}
}