【问题标题】:get the value of dynamically generated multiple edittext using gettext in android在android中使用gettext获取动态生成的多个edittext的值
【发布时间】:2013-04-19 10:41:35
【问题描述】:

我希望在多个编辑文本上设置文本值,单击按钮。编辑文本是动态生成的,我想要每个特定编辑文本的值。并将该文本值存储在字符串数组中。这是代码。

if (type.equalsIgnoreCase("Edittext")) {
                Question = cursor1.getString(cursor1
                        .getColumnIndex(AndroidOpenDbHelper.QUESTIONS));
                String ID = cursor1.getString(cursor1
                        .getColumnIndex(AndroidOpenDbHelper.ID));
                // ll_layout1 = (LinearLayout)
                // findViewById(R.id.linearlayout1);
                tv_edittext = new TextView(this);
                tv_edittext.setTextSize(20.0f);
                tv_edittext.setText(Question);
                ll_layout1.addView(tv_edittext);
                et = new EditText(this);
                et.setOnClickListener(this);
                et.setId(EDITTEXT);
                et.setMinLines(1);
                et.setMaxLines(3);
                // editTextList.add(et);
                ll_layout1.addView(et);
                // editTextList.add(et);

                typelist.add(Question);

            }

这段代码生成Text和edittext如何开始...? 提前致谢。

【问题讨论】:

标签: android android-edittext


【解决方案1】:

改成

tv_edittext = new MyTextView(this);

MyTextView 在哪里:

public class MyTextView extends TextView{

    public SampleEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
        this.addTextChangedListener(new MyTextWatcher());
    }

    public SampleEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        this.addTextChangedListener(new MyTextWatcher());
    }

    public SampleEditText(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.addTextChangedListener(new MyTextWatcher());
    }

}

按如下方式使用文本观察器:

public class MyTextWatcher implements TextWatcher {

}

无论你动态创建多少个textview,都会为其创建一个watcher,你可以在textwatcher的onTextChanged方法中获取正在输入的文本。

【讨论】:

    猜你喜欢
    • 2015-12-15
    • 1970-01-01
    • 2018-02-05
    • 2021-01-18
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2017-10-14
    • 2015-03-09
    相关资源
    最近更新 更多