【问题标题】:Dynamically add Edit Text and have their references动态添加编辑文本并有他们的参考
【发布时间】:2015-11-09 23:07:59
【问题描述】:

我希望能够在运行时添加编辑文本,并通过单击某个按钮获得它们的引用。实现它的最佳方法是什么?

【问题讨论】:

    标签: java android mobile-application


    【解决方案1】:

    摆弄这个:

    private void buildEditText() {
        LinearLayout layout = new LinearLayout(getActivity());
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layout.setLayoutParams(layoutParams);
        layout.setOrientation(LinearLayout.VERTICAL);
    
        EditText editText = (EditText) inflater.inflate(R.layout.your_custom_layout, null); // Here is your reference
        LayoutParams textViewParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        editText .setLayoutParams(textViewParams);
        layout.addView(textView);
        this.editText = editText ;
        this.editText .setImeOptions(EditorInfo.IME_ACTION_DONE);
        editText .setText("If you have some text to enter");
    
        editText .setHint("Some hint");
        editText .setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS); 
    
        parentView.addView(layout);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 2013-09-03
      • 2016-07-22
      • 1970-01-01
      相关资源
      最近更新 更多