为了账号安全,请及时绑定邮箱和手机立即绑定

Android:以编程方式将textview添加到线性布局

Android:以编程方式将textview添加到线性布局

温温酱 2019-09-02 14:54:38
我试图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我该怎么做?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 593 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信