在这里,我有一个很好的简单表布局来显示数据库的内容。
<?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,但都没有用。提前致谢。
使用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] 删除。
我来说两句