如何在Android嵌入式卡中设置setText()

迈克尔·Android·新手

在这里,我有一个很好的简单表布局来显示数据库的内容。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/tableLayout1">

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date"
            android:id="@+id/Date"
            android:layout_weight="0.3333"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Systolic"
            android:id="@+id/Systolic"
            android:layout_weight="0.3333"
            android:textAlignment="center" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Diastolic"
            android:id="@+id/Diastolic"
            android:layout_weight="0.3333" />
    </TableRow>
    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/DateInfo"
            android:layout_weight="0.3333"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/SystolicInfo"
            android:layout_weight="0.3333"
            android:textAlignment="center" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/DiastolicInfo"
            android:layout_weight="0.3333" />
    </TableRow>
</TableLayout>

这是在调用活动的onCreate中调用的方法:

private View buildView() {
    //CardBuilder card = new CardBuilder(this, CardBuilder.Layout.MENU);
    //card.setText("It worked!!!");
    CardBuilder previousReadings = new CardBuilder(this, CardBuilder.Layout.EMBED_INSIDE);
    previousReadings.setEmbeddedLayout(R.layout.blood_pressures);

    TextView tv = (TextView) findViewById(R.id.SystolicInfo);
    //tv.setText("Why won't this work?");
    MyDatabase info = new MyDatabase(this);
    info.open();
    String data = info.getData();
    info.close();
    System.out.println(data);
    //tv.setText(data);

    return previousReadings.getView();
    //return card.getView();
}
}

我使用了CarBuilder对象卡,它是没有嵌入式布局的简单卡,效果很好。然后,我将其注释掉,并尝试实现也可以正常工作的嵌入式卡(上述)。但是,当我尝试使用tv.setText()时,就会出现问题。这仅仅是一个常量还是“数据”变量。logcat读取“无法加载Activity:...空指针异常。

有人可以阐明这个问题吗?我已经尝试过EditTexts以及TextViews,但都没有用。提前致谢。

ρяσsρєяK

使用previousReadings.getView()通话findViewById从Card访问TextView:

....
System.out.println(data);
View view= previousReadings.getView();
TextView tv = (TextView)view.findViewById(R.id.SystolicInfo);
tv.setText("Why won't this work?");
return view;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在C ++中嵌入Chromium嵌入式框架

如何在Google Chrome浏览器的嵌入式Javascript中设置断点?

如何在Spring Boot中为嵌入式Jetty设置处理程序?

如何在Spring Boot和嵌入式Tomcat中设置mod_reqtimeout?

如何在Qt中为嵌入式设备设置poppler库?

如何在Spring Boot中设置嵌入式tomcat的日志记录级别?

如何在嵌入式数组mongodb中查询嵌入式文档

如何在嵌入式tomcat中添加ServletContextListener

如何在嵌入式文档中查找某个元素

如何在WKWebView中启用嵌入式YouTube视频?

如何在 MongoDb 中查询嵌入式文档?

如何在嵌入式CSS中编写a:hover?

如何在嵌入式函数中存储值

如何在Go中读取嵌入式字段?

如何在jQuery中调用嵌入式函数?

如何在SVG中制作嵌入式投影

如何在mongodb中搜索嵌入式文档?

如何在嵌入式Jetty中配置ErrorPageErrorHandler?

如何在Meteor中循环浏览嵌入式文档

如何在Spring Boot嵌入式tomcat中设置HTTPS SSL密码套件首选项

neo4j ::如何在嵌入式模型中设置短路径查询超时属性?

在 android Chrome 自定义选项卡中禁用嵌入式媒体

更改嵌入式TabBarController中的选项卡

如何在Windows 10上为嵌入式Python设置virtualenv

如何在嵌入式 <object> 标签内设置链接样式

如何在嵌入式设备上设置 FTP 客户端连接?

如何使用Javascript定性设置嵌入式数据

如何使用嵌入式Cassandra和Rexster设置Titan

如何在MongoDB中的嵌入式数组对象中插入json对象?