用的EditText删除选项 [英] EditText with delete option

查看:184
本文介绍了用的EditText删除选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜请领我一些例子演示了如何使用创建EDITTEXT删除按钮,当点击删除选项,将删除创建EDITTEXT。在此先感谢...

code动态创建文本编辑。

 的LinearLayout rAlign =(的LinearLayout)findViewById(R.id.lId);
        的EditText newPass =新的EditText(getApplicationContext());
        allEds.add(newPass);
        newPass.setHint(标签名称);
        newPass.setLayoutParams(新的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(); //添加微调功能


解决方案

布局可能是这样的:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =match_parent><的EditText
    机器人:ID =@ + ID / editText1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentTop =真
    机器人:layout_marginTop =50dp
    机器人:EMS =10>    < requestFocus的/>
< /&的EditText GT;<按钮
    机器人:ID =@ + ID /按钮1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignBaseline =@ + ID / editText1
    机器人:layout_alignBottom =@ + ID / editText1
    机器人:layout_toRightOf =@ + ID / editText1
    机器人:文字=按钮/>

和Java可能是这样的:

 公共类MainActivity扩展活动实现OnClickListener {TextView的电视;
按钮BTN;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    BTN =(按钮)findViewById(R.id.button1);
    电视=(的TextView)findViewById(R.id.editText1);    btn.setOnClickListener(本);
}@覆盖
公共无效的onClick(视图v){    tv.setVisibility(View.GONE);}

}

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 

解决方案

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);

}

}

这篇关于用的EditText删除选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆