vendredi 27 février 2015

how to setText() in android embedded card

Here I have a nice simple table layout to display the contents of my database.



<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://ift.tt/nIICcg"
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>


Here is the method that is called in the onCreate of the calling activity:



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();
}
}


I used the CarBuilder object card that was a simple card without an embedded layout and this worked fine. I then commented it out and tried implementing the embedded card which also works fine (above). However the problem arises when I try to tv.setText(). Whether this is just a constant or the "data" variable. The logcat reads "unable to load Activity:... null pointer exception.


Can anybody shed some light on the problem? I have tried EditTexts as well as TextViews and neither work. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire