有人可以帮我....我正在尝试使用数据库中的一些值填充表格,每次收到分数时都会更新...由于某种原因,我的表格没有更新为新分数。
这是我的代码:(提前感谢)
**/**
*
*/
package group6.scoresheet;
import group6.scoresheet.model.DataStore;
import group6.scoresheet.model.Game;
import group6.scoresheet.model.GamePlayer;
import group6.scoresheet.model.GameTeam;
import group6.scoresheet.model.Player;
import group6.scoresheet.model.Team;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
/**
* This displays the Team's scores.
* Called when the user clicks the Team stats tab
* @author NiraliPatel
*
*/
public class TeamStatistics extends Activity {
private Team team1 = null;
private Team team2 = null;
private int teamOne = 0;
private int teamTwo = 1;
private DataStore dataStore = null;
Game game;
Player player;
Team team;
TableLayout t1;
TableLayout t2;
/** Called when the activity is created */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.team_stats);
this.dataStore = (DataStore)getApplicationContext();
game = dataStore.getCurrentGame();
// Get the two teams that are playing
Bundle extras = getIntent().getExtras();
if(extras != null)
{
this.teamOne = extras.getInt("teamOne");
this.teamTwo = extras.getInt("teamTwo");
}
this.team1 = this.dataStore.getTeams().get(this.teamOne);
this.team2 = this.dataStore.getTeams().get(this.teamTwo);
populate();
}
/**
* Populates the lists with the Teams scores
*/
public void populate()
{
Team team1 = getTeam(1);
Team team2 = getTeam(2);
TextView team1Name = (TextView) findViewById(R.id.Team1);
team1Name.setText(team1.getName());
TextView team2Name = (TextView) findViewById(R.id.Team2);
team2Name.setText(team2.getName());
Map<Team, Integer> score_1 = this.game.getScore();
String[] scoreType = {"Total Score:", "Home Runs:", "Total Balls:", "Total Outs:"};
String[] t1Scores = {Integer.toString(score_1.get(this.team1)), "0", "0", "0"};
String[] t2Scores = {Integer.toString(score_1.get(this.team2)), "0", "0", "0"};
t1 = (TableLayout)findViewById(R.id.tableTeamDataT1);
for(int i = 0; i < scoreType.length; i++){
teamRow(t1, scoreType[i] , t1Scores[i]);
}
t2 = (TableLayout)findViewById(R.id.tableTeamDataT2);
for(int i = 0; i < scoreType.length; i++){
teamRow(t2, scoreType[i] , t2Scores[i]);
}
}
public void teamRow(TableLayout table, String col1, String col2){
TableRow tr1 = new TableRow(this);
//Create text views to be added to the row.
TextView tvScore = new TextView(this);
TextView tvScoreValue = new TextView(this);
//Put the data into the text view by passing it to a user defined function createView()
createView(tr1, tvScore, col1);
createView(tr1, tvScoreValue, col2);
/**if(heading){
tr1.setBackgroundColor(Color.WHITE);
//tr1.setGravity(5);
tvName.setTextColor(Color.BLACK);
tvRbi.setTextColor(Color.BLACK);
tvHomeRuns.setTextColor(Color.BLACK);
}*/
//Add the new row to our tableLayout tl
table.addView(tr1);
}
public void createView(TableRow tr1, TextView t, String viewdata) {
t.setText(viewdata);
tr1.addView(t); // add TextView to row.
}
/**
* Gets a team given the team number
* @param teamNumber The number of the team to be selected (1 for team 1, 2 for team 2)
* @return The team
*/
private Team getTeam(int teamNumber)
{
Team team = null;
switch(teamNumber)
{
case 1:
team = this.team1;
break;
case 2:
team = this.team2;
break;
}
return team;
}
public void onResume(){
super.onResume();
//populate();
}
}
**
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF004000"
android:gravity="right"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/TeamStatsHeader" >
<RelativeLayout
android:id="@+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/tableTeamDataT1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:layout_toLeftOf="@+id/Team2"
android:stretchColumns="0,1,2" >
<TableRow
android:id="@+id/tableTeamRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<TextView
android:id="@+id/Team1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/Teams"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TableLayout
android:id="@+id/tableTeamDataT2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_below="@id/Team2"
android:layout_toRightOf="@+id/tableTeamDataT1"
android:stretchColumns="0,1,2" >
<TableRow
android:id="@+id/tableTeamRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<TextView
android:id="@+id/Team2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="102dp"
android:text="@string/Teams"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</ScrollView>
<TextView
android:id="@+id/TeamStatsHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/TeamStats"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="40dp" />
<Button
android:id="@+id/finish_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/TeamStatsHeader"
android:layout_alignParentBottom="true"
android:layout_marginLeft="52dp"
android:text="@string/Continue" />
</RelativeLayout>