Android 从动态创建的编辑文本中检索值和显示

Android 从动态创建的编辑文本中检索值和显示,android,Android,当我点击时,我有一个按钮,当我输入一个值时,它将显示edittext,但我无法显示输入的值,以显示我使用textview但无法显示的值 class DynamicbuttonActivity extends Activity { TextView view= new TextView(getApplicationContext()); public void onCreate(Bundle savedInstanceState) { super.onCreat

当我点击时,我有一个按钮,当我输入一个值时,它将显示edittext,但我无法显示输入的值,以显示我使用textview但无法显示的值

class DynamicbuttonActivity extends Activity {

    TextView view= new TextView(getApplicationContext());

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScrollView scrl=new ScrollView(this);

        final LinearLayout ll=new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        scrl.addView(ll);

        Button add_btn=new Button(this);
        add_btn.setText("Click to add EditTexts");
        ll.addView(add_btn);

        Button add_btn1=new Button(this);
        add_btn1.setText("Click to view TextViiews");
        ll.addView(add_btn1);

        add_btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v)  { 
                EditText et=new EditText(getApplicationContext());
                ll.addView(et);
            }
        });

        add_btn1.setOnClickListener(new OnClickListener()  {    
            String strg;
            public void onClick(View v)  {
                strg = et.getText().toString();
                view.setText(strg);
                ll.addView(view);    
            }
        });

        this.setContentView(scrl);
    }  
}

你能帮帮我吗?

你的实现方式不对。首先单击按钮,它将添加
EditText
,但这是您在
onclick
方法中定义的,因此您不会进入另一个
onclick
方法,它的范围仅限于第一个
onclick
方法

第二件事每次你们点击第一个按钮,它会在你们的版面中添加编辑文本。我不明白你对这个代码的定义。我的意思是,当用户在
edittext
上输入文本,然后单击要在
TextView
中显示的值的按钮,然后只需删除第一个按钮,并在
onclick
方法之外定义
edittext
,就像声明
TextView

public class DynamicbuttonActivity extends Activity {

    TextView view= new TextView(getApplicationContext());
    EditText et=new EditText(getApplicationContext());

    public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);

        ScrollView scrl=new ScrollView(this);

        final LinearLayout ll=new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        scrl.addView(ll);

        /*Button add_btn=new Button(this);
        add_btn.setText("Click to add EditTexts");
        ll.addView(add_btn);*/
        Button add_btn1=new Button(this);
        add_btn1.setText("Click to view TextViiews");
        ll.addView(add_btn1);
        /*add_btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v){ 
            }

        });*/

        add_btn1.setOnClickListener(new OnClickListener() { 
            String strg;
            public void onClick(View v){
                strg = et.getText().toString();
                view.setText(strg);
            }

        });
        ll.addView(et);
        ll.addView(view);
        this.setContentView(scrl);

    }

}

那么,如何显示我在edittext
TextView视图=新的TextView(getApplicationContext())中输入的值不好。在
OnCreate()
中初始化这些。