TextViewsコードでxml定義のレイアウトに追加しようとしています。多くのViewsものが定義されているxml-sheetがあります。しかし、コードにいくつかのビューを追加する必要があるためLinearLayout、xml-sheetにを作成します。
<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どうすればできますか?
助けてくれてありがとう。マーティン
setContentView(R.layout.your_xml_layout);本当に正しいXMLをロードしますか?あなたがandroid:id="@+id/info"たまたまTextView を使用している他のxmlレイアウトはありますか?