Android EditText动态

时间:2015-10-20 06:45:09

标签: android android-edittext

我动态创建EditText,但当我点击它们插入数据时,键盘无法打开。

MaterialEditText ed = new MaterialEditText(getApplicationContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(0, 20, 30, 0);
rlCampi.addView(ed, layoutParams);

2 个答案:

答案 0 :(得分:0)

试试这个

youredittextname.setFocusableInTouchMode(true);
    youredittextname.requestFocus();

答案 1 :(得分:0)

要添加编辑文本,请尝试以下方法:

// Pass it an Activity or Context
    EditText myEditText = new EditText(context); 
// Pass two args; must be LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, or an integer pixel value.
    myEditText.setLayoutParams(new LayoutParams(..., ...)); 
    myLayout.addView(myEditText);