Hi folks, I'm somewhat of an android coding noob, but I thought the good folk here at androidforums.com might be able to help me or at least point me in the right direction to solve my problem.
I'm currently trying to develop a (rather simplistic) scoring app for archery. I've made the scoring code work properly, it even puts the scores into a database and everything! I'm having trouble displaying the scores though. I want to use an activity that displays a score table, which is updated after every round is finished with a new row containing all the scores from each shot in that round, and a total column.
I've used a TableLayout to create my table, declared in the main.xml file and I've written another xml file TableRow, which is to be added to the TableLayout each time the "finish" button is clicked. This works well. However, all I can manage at the moment is to add the row, I can't edit any of the values in it; this means I end up with a beautiful row full of "-" (which is my default string for an empty cell, so I know it's worked).
When I try to change the values by using setText() (after using findViewById() to change the relevent text) the app force closes.
Please help!
Here's my code for the row to be added
and here's the .java file which is supposed to change the text of the row. At the moment it's just a proof of concept program, I'll integrate it into my actual software when I get it working.
All those declared variables are meant to be the textViews I want to change, but I haven't got one working yet so I haven't implemented changing them all.
I'm currently trying to develop a (rather simplistic) scoring app for archery. I've made the scoring code work properly, it even puts the scores into a database and everything! I'm having trouble displaying the scores though. I want to use an activity that displays a score table, which is updated after every round is finished with a new row containing all the scores from each shot in that round, and a total column.
I've used a TableLayout to create my table, declared in the main.xml file and I've written another xml file TableRow, which is to be added to the TableLayout each time the "finish" button is clicked. This works well. However, all I can manage at the moment is to add the row, I can't edit any of the values in it; this means I end up with a beautiful row full of "-" (which is my default string for an empty cell, so I know it's worked).
When I try to change the values by using setText() (after using findViewById() to change the relevent text) the app force closes.
Please help!
Here's my code for the row to be added
<?xml version="1.0" encoding="utf-8"?>
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center"
android:id="@+id/gap_filler"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview1"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview2"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview3"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview4"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview5"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview6"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/total_textview"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</TableRow>
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center"
android:id="@+id/gap_filler"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview1"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview2"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview3"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview4"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview5"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/my_textview6"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:layout_gravity="center"
android:id="@+id/total_textview"
android:text="-"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</TableRow>
and here's the .java file which is supposed to change the text of the row. At the moment it's just a proof of concept program, I'll integrate it into my actual software when I get it working.
All those declared variables are meant to be the textViews I want to change, but I haven't got one working yet so I haven't implemented changing them all.
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
public class messing extends Activity {
private int endNo = 1;
private int shot1 = 0;
private int shot2 = 0;
private int shot3 = 0;
private int shot4 = 0;
private int shot5 = 0;
private int shot6 = 0;
private int total = 0;
private TextView tvEnd;
private TextView tvShot1;
private TextView tvShot2;
private TextView tvShot3;
private TextView tvShot4;
private TextView tvShot5;
private TextView tvShot6;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
final TableLayout tl = (TableLayout) findViewById(R.id.myTableLayout);
//This button adds a row to the table. The row is a seperate xml file.
Button newRow = (Button) findViewById(R.id.new_row_button);
newRow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
inflater.inflate(R.layout.tablerow, tl);
;
endNo++;
}
});
//The code I'm trying to use to add text to my score row
Button fillText = (Button) findViewById(R.id.fill_button);
fillText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TextView peas = (TextView) findViewById(R.id.gap_filler);
peas.setText(endNo);
endNo++;
}
});
}
}
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
public class messing extends Activity {
private int endNo = 1;
private int shot1 = 0;
private int shot2 = 0;
private int shot3 = 0;
private int shot4 = 0;
private int shot5 = 0;
private int shot6 = 0;
private int total = 0;
private TextView tvEnd;
private TextView tvShot1;
private TextView tvShot2;
private TextView tvShot3;
private TextView tvShot4;
private TextView tvShot5;
private TextView tvShot6;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
final TableLayout tl = (TableLayout) findViewById(R.id.myTableLayout);
//This button adds a row to the table. The row is a seperate xml file.
Button newRow = (Button) findViewById(R.id.new_row_button);
newRow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
inflater.inflate(R.layout.tablerow, tl);
;
endNo++;
}
});
//The code I'm trying to use to add text to my score row
Button fillText = (Button) findViewById(R.id.fill_button);
fillText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TextView peas = (TextView) findViewById(R.id.gap_filler);
peas.setText(endNo);
endNo++;
}
});
}
}