I have a TableLayout, in which rows are dynamically created, thus it may cross the limited screen size. To avoid this I am trying to add a scroll view after creating the table layout as:
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout1);
ScrollView sv = new ScrollView(this);
tl.addView(sv);
for (i = 0; i < count; i++) {
TableRow tr = new TableRow(this);
.
.
.
. //finally iam adding this table row to layout.
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(getApplicationContext(),
SmsActivity.class);
// setMessageBody((String) tvf.getContentDescription());
// submit.setEnabled(false);
String messageText = (String) valueTV.getText();
String dateText = (String) labelTV.getText();
myIntent.putExtra("messageText",dateText+"\n"+message);
startActivity(myIntent);
}});
}
However the application is getting force closed if the number of rows increases more than the size of display.
My log cat shows the error as
06-28 14:41:49.533: ERROR/AndroidRuntime(1256): Caused by: java.lang.StringIndexOutOfBoundsException
What is the problem and how can I fix it?
You need to add the TableLayout to the ScrollView, and not the other way around.