I am creating a TableRow at runtime. The trouble I have is that I have 6 TextViews created and added to the TableRow but for some reason only 3 of the TextViews appear, the 1st 2 and the last one. I know that there is no problem adding the TextView to the TableRow because if I comment out the last 2 TextViews the fourth one still overwrites the third. Because of this it seems to be that there is a limit somewhere on the number of columns I can add to this TableRow.
Any ideas where I am going wrong?
Here is my java
public class locationlist extends Activity {
/** Called when the activity is first created. */
private locationListDbAdapter mDbHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationlist);
mDbHelper = new locationListDbAdapter(this);
mDbHelper.open();
String id = mDbHelper.fetchRow(1).getString(0);
String locationText = mDbHelper.fetchRow(1).getString(1);
String localCode = mDbHelper.fetchRow(1).getString(2);
String localService = mDbHelper.fetchRow(1).getString(3);
String localComments = mDbHelper.fetchRow(1).getString(4);
String localNextes = mDbHelper.fetchRow(1).getString(5);
TextView idView = new TextView(this);
idView.setText(id);
TextView locationView = new TextView(this);
locationView.setText(locationText);
TextView codeView = new TextView(this);
codeView.setText(localCode);
TextView serviceView = new TextView(this);
codeView.setText(localService);
TextView comments开发者_如何学PythonView = new TextView(this);
codeView.setText(localComments);
TextView nextesView = new TextView(this);
codeView.setText(localNextes);
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow r2 = new TableRow(this);
r2.addView(idView);
r2.addView(locationView);
r2.addView(codeView);
r2.addView(serviceView);
r2.addView(commentsView);
r2.addView(nextesView);
tl.addView(r2);
this.setContentView(tl);
This is the xml file I am pointing it at
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content">
<TableRow android:layout_height="wrap_content" android:id="@+id/tableRow1" android:layout_width="fill_parent">
<TextView android:id="@+id/textView11" android:layout_height="wrap_content" android:text="ID" android:layout_width="0dip" android:layout_weight="0.1"></TextView>
<TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Location" android:layout_width="0dip" android:layout_weight="0.4"></TextView>
<TextView android:id="@+id/textView2" android:layout_height="wrap_content" android:text="Type" android:layout_width="0dip" android:layout_weight="0.15"></TextView>
<TextView android:id="@+id/textView3" android:layout_height="wrap_content" android:text="Service" android:layout_width="0dip" android:layout_weight="0.2"></TextView>
<TextView android:id="@+id/textView4" android:layout_height="wrap_content" android:text="Comments" android:layout_weight="0.3" android:layout_width="0dip"></TextView>
<TextView android:id="@+id/textView5" android:layout_height="wrap_content" android:text="ES" android:layout_width="0dip" android:layout_weight="0.15"></TextView>
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
</TableLayout>
Why do you have the following lines? You set your codeView TextView to localCode's text, then you overwrite that three times for no discernible reason:
codeView.setText(localCode);
codeView.setText(localService);
codeView.setText(localComments);
codeView.setText(localNextes);
Your serviceView, commentsView and nextesView TextView's all appear to be blank, you never do anything like this:
serviceView.setText(localService);
commentsView.setText(localComments);
nextesView.setText(localNextes);
I would temporarily replace your database stuff with test strings so as to narrow down the error, see if it is still failing, if not, work on the things mentioned above, test again, if it is working now, replace the temporary text strings with the database stuff.
精彩评论