我试图TextViews在代码中添加到我的xml定义的布局。我有一个xml表,其中Views定义了很多。但是我必须在代码中添加一些视图,所以LinearLayout在xml-sheet中创建一个:<LinearLayoutxmlns: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我该怎么做?
添加回答
举报
0/150
提交
取消