I have one EditText defined in xml and I want to add another one dynamically but when the app runs, the dynamically added behaves like TextView. I can't type in any text and no caret shows. It doesn't even look like EditText that I include statically. See the image.
I have latest Android Studio, latest emulators, tried it on API 28 and also on physical device Samsung S8+ API 26 and it works same weird way everywhere. And worst is that I'm sure in the past it worked.
Any idea please how I could find out what's wrong? Fix it?
Code:
public class TActivity extends AppCompatActivity {
private LinearLayout Layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.t);
Layout = (LinearLayout) findViewById(R.id.Layout);
EditText Textbox = new EditText(this);
Textbox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Textbox.setText("My text");
//Textbox.setEnabled(true);
Layout.addView(Textbox);
}
}
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/ThisWorks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"/>
</LinearLayout>