我希望能够在运行时添加“编辑文本”,并通过单击某个按钮来显示其引用。实现它的最佳方式是什么?
答案 0 :(得分:0)
弄清楚这一点:
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);
}