Jelmerholland
Lurker
Hello guys,
I'm not sure if I'm in the rigth spot right now.. so.. let's hope I am..
I have code which creates 9 buttons (1 to 9) in a <TableLayout> (created in a for-loop). But now I'd like to add a TextView element above the 9 buttons to display what you've pressed (or what so ever). It's my first app on android ever, so this is completely new to me. (We HAVE to make an android app for my study... so please help).
What's not working.. the TextView. I'm trying to get this through a xml file in the layout folder, but it's not working.
This is de code from the usefull lines:
Why I'd like to do this throughout the xml file? Well.. I saw you have to use the xml files, it's better for you (as a developer) and when you have to edit something quick it's easier.. especially with huge apps. But for now.. I have to make a span of 3, because the result has to be in 1 row but also in 3 columns. And not in the first column in the upper row. So.. to accomplish the 'span' I have to use xml because there is no such function in the android packages (googled)
As you can see in the code, currently I'm sin g a TextView created IN the .java file, but as you can see also.. line 1 is commented.. That's what I'm trying to use, but the app just crashes and says: sorry, can't help ya...
I hope you understand what I'm trying to accomplish and I hope that you can help me.
If you need more code/information or if you want me to be more specific, don't hesitate to ask
I'm not sure if I'm in the rigth spot right now.. so.. let's hope I am..
I have code which creates 9 buttons (1 to 9) in a <TableLayout> (created in a for-loop). But now I'd like to add a TextView element above the 9 buttons to display what you've pressed (or what so ever). It's my first app on android ever, so this is completely new to me. (We HAVE to make an android app for my study... so please help).
What's not working.. the TextView. I'm trying to get this through a xml file in the layout folder, but it's not working.
This is de code from the usefull lines:
Code:
//resultBox = (TextView) findViewById(R.id.result_box);
resultBox = new TextView(this);
resultBox.setText("Hello World!");
tr = new TableRow(this);
tr.addView(resultBox);
buttonTable.addView(tr,300,40);
for( int i = 1; i <= 3; i++ )
{
tr = new TableRow(this);
for( int c = 1; c <= 3; c++)
{
btn = new Button(this);
btn.setText("" + (c*i));
btn.setTextSize(10);
btn.setTextColor(Color.rgb(255, 50, 0));
btn.setOnClickListener(this);
tr.addView(btn, btnSize, btnSize);
}
buttonTable.addView(tr);
}
super.setContentView(buttonTable);
Why I'd like to do this throughout the xml file? Well.. I saw you have to use the xml files, it's better for you (as a developer) and when you have to edit something quick it's easier.. especially with huge apps. But for now.. I have to make a span of 3, because the result has to be in 1 row but also in 3 columns. And not in the first column in the upper row. So.. to accomplish the 'span' I have to use xml because there is no such function in the android packages (googled)
As you can see in the code, currently I'm sin g a TextView created IN the .java file, but as you can see also.. line 1 is commented.. That's what I'm trying to use, but the app just crashes and says: sorry, can't help ya...

I hope you understand what I'm trying to accomplish and I hope that you can help me.
If you need more code/information or if you want me to be more specific, don't hesitate to ask
