【发布时间】:2015-11-09 23:07:59
【问题描述】:
我希望能够在运行时添加编辑文本,并通过单击某个按钮获得它们的引用。实现它的最佳方法是什么?
【问题讨论】:
标签: java android mobile-application
我希望能够在运行时添加编辑文本,并通过单击某个按钮获得它们的引用。实现它的最佳方法是什么?
【问题讨论】:
标签: java android mobile-application
摆弄这个:
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);
}
【讨论】: