TextViews
コードで xml 定義のレイアウトに追加しようとしています。多くのViews
ものが定義されているxmlシートがあります。LinearLayout
ただし、コードにいくつかのビューを追加する必要があるため、xml-sheet にa を作成します。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:id="@+id/info"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
そして、このレイアウトでは、次のように追加したいと思いTextView
ます:
View linearLayout = findViewById(R.id.info);
//LinearLayout layout = (LinearLayout) findViewById(R.id.info);
TextView valueTV = new TextView(this);
valueTV.setText("hallo hallo");
valueTV.setId(5);
valueTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
((LinearLayout) linearLayout).addView(valueTV);
しかし、次のエラーメッセージしか表示されません。
: java.lang.ClassCastException: android.widget.TextView
どうすればいいですか?
助けてくれてありがとう。マーティン