gpt4 book ai didi

java - 方法 updateGames 类中的 GamesActivity 不能为 App

转载 作者:行者123 更新时间:2023-12-02 11:13:59 27 4
gpt4 key购买 nike

我正在尝试使用对话框中的一些附加 EditText 字段更新 SQLite 数据库表。我如何在更新游戏表的所有五行中收到以下错误消息。

错误:GamesActivity 类中的方法 updateGames 无法应用错误:GamesActivity 类中的 updateGames 方法无法应用于给定类型;必需:int,int,int,int,int,int,int,String发现:字符串,整数原因:实际参数列表和形式参数列表的长度不同

我知道我很可能错误地为 updateGame 方法创建了参数。由于我对 Javascript 和 Android 编程相当陌生,我似乎找不到纠正这个问题的方法。当我查看 DatabaseHelper 时,我可以看到该方法从未被调用或使用。我假设这是因为我的论点是错误的。

我在下面列出了我的代码。如果有人能看一下并指出我做错了什么,我将不胜感激。

DatabaseHelper.java

import rvogl.ca.tpcui.Database.Models.Bowler;
import rvogl.ca.tpcui.Database.Models.League;
import rvogl.ca.tpcui.Database.Models.Series;
import rvogl.ca.tpcui.Database.Models.Games;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "tpc_database";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL(League.CREATE_TABLE);
db.execSQL(Bowler.CREATE_TABLE);
db.execSQL(Series.CREATE_TABLE);
db.execSQL(Games.CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + League.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Bowler.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Series.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + Games.TABLE_NAME);
onCreate(db);
}

//League Methods
public long insertLeague(String league) {
//Get Writable Database That We Want To Write Data Too
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(League.COLUMN_NAME, league);
long id = db.insert(League.TABLE_NAME, null, values);
db.close();
return id;
}

public League getLeague(long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(League.TABLE_NAME,
new String[]{League.COLUMN_ID, League.COLUMN_NAME, League.COLUMN_TIMESTAMP},
League.COLUMN_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);

if (cursor != null)
cursor.moveToFirst();

League league = new League(
cursor.getInt(cursor.getColumnIndex(League.COLUMN_ID)),
cursor.getString(cursor.getColumnIndex(League.COLUMN_NAME)),
cursor.getString(cursor.getColumnIndex(League.COLUMN_TIMESTAMP)));
cursor.close();
return league;
}

public List<League> getAllLeagues() {
List<League> leagues = new ArrayList<>();
String selectQuery = "SELECT * FROM " + League.TABLE_NAME + " ORDER BY " +
League.COLUMN_TIMESTAMP + " DESC";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
League league = new League();
league.setId(cursor.getInt(cursor.getColumnIndex(League.COLUMN_ID)));
league.setName(cursor.getString(cursor.getColumnIndex(League.COLUMN_NAME)));
league.setTimestamp(cursor.getString(cursor.getColumnIndex(League.COLUMN_TIMESTAMP)));

leagues.add(league);
} while (cursor.moveToNext());
}
db.close();
return leagues;
}

public int getLeaguesCount() {
String countQuery = "SELECT * FROM " + League.TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);

int count = cursor.getCount();
cursor.close();
return count;
}

public int updateLeague(League league) {
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(League.COLUMN_NAME, league.getName());
return db.update(League.TABLE_NAME, values, League.COLUMN_ID + " = ?",
new String[]{String.valueOf(league.getId())});
}

public void deleteLeague(League league) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(League.TABLE_NAME, League.COLUMN_ID + " = ?",
new String[]{String.valueOf(league.getId())});
db.close();
}

//Bowler Methods
public long insertBowler(String bowler) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Bowler.COLUMN_NAME, bowler);
long id = db.insert(Bowler.TABLE_NAME, null, values);
db.close();

return id;
}
public Bowler getBowler(long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(Bowler.TABLE_NAME,
new String[]{Bowler.COLUMN_ID, Bowler.COLUMN_LEAGUE_ID, Bowler.COLUMN_NAME, Bowler.COLUMN_TIMESTAMP},
Bowler.COLUMN_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);

if (cursor != null)
cursor.moveToFirst();
Bowler bowler = new Bowler(
cursor.getInt(cursor.getColumnIndex(Bowler.COLUMN_ID)),
cursor.getInt(cursor.getColumnIndex(Bowler.COLUMN_LEAGUE_ID)),
cursor.getString(cursor.getColumnIndex(Bowler.COLUMN_NAME)),
cursor.getString(cursor.getColumnIndex(Bowler.COLUMN_TIMESTAMP)));
cursor.close();
return bowler;
}
public List<Bowler> getAllBowlers() {
List<Bowler> bowlers = new ArrayList<>();
String selectQuery = "SELECT * FROM " + Bowler.TABLE_NAME + " ORDER BY " +
Bowler.COLUMN_TIMESTAMP + " DESC";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
Bowler bowler = new Bowler();
bowler.setId(cursor.getInt(cursor.getColumnIndex(Bowler.COLUMN_ID)));
bowler.setLeagueId(cursor.getInt(cursor.getColumnIndex(Bowler.COLUMN_LEAGUE_ID)));
bowler.setName(cursor.getString(cursor.getColumnIndex(Bowler.COLUMN_NAME)));
bowler.setTimestamp(cursor.getString(cursor.getColumnIndex(Bowler.COLUMN_TIMESTAMP)));

bowlers.add(bowler);
} while (cursor.moveToNext());
}
db.close();
return bowlers;
}

public int getBowlersCount() {
String countQuery = "SELECT * FROM " + Bowler.TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int count = cursor.getCount();
cursor.close();
return count;
}

public int updateBowler(Bowler bowler) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Bowler.COLUMN_NAME, bowler.getName());
return db.update(Bowler.TABLE_NAME, values, Bowler.COLUMN_ID + " = ?",
new String[]{String.valueOf(bowler.getId())});
}

public void deleteBowler(Bowler bowler) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(Bowler.TABLE_NAME, Bowler.COLUMN_ID + " = ?",
new String[]{String.valueOf(bowler.getId())});
db.close();
}

//Series Methods
public long insertSeries(String series) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Series.COLUMN_NAME, series);
long id = db.insert(Series.TABLE_NAME, null, values);
db.close();
return id;
}

public Series getSeries(long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(Series.TABLE_NAME,
new String[]{Series.COLUMN_ID, Series.COLUMN_LEAGUE_ID, Series.COLUMN_NAME, Series.COLUMN_TIMESTAMP},
Series.COLUMN_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);

if (cursor != null)
cursor.moveToFirst();
Series series = new Series(
cursor.getInt(cursor.getColumnIndex(Series.COLUMN_ID)),
cursor.getInt(cursor.getColumnIndex(Series.COLUMN_LEAGUE_ID)),
cursor.getString(cursor.getColumnIndex(Series.COLUMN_NAME)),
cursor.getString(cursor.getColumnIndex(Series.COLUMN_TIMESTAMP)));
cursor.close();
return series;
}

public List<Series> getAllSeries() {
List<Series> series = new ArrayList<>();
String selectQuery = "SELECT * FROM " + Series.TABLE_NAME + " ORDER BY " +
Series.COLUMN_TIMESTAMP + " DESC";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

//Looping Through All Rows And Adding To The List
if (cursor.moveToFirst()) {
do {
Series series1 = new Series();
series1.setId(cursor.getInt(cursor.getColumnIndex(Series.COLUMN_ID)));
series1.setLeagueId(cursor.getInt(cursor.getColumnIndex(Series.COLUMN_LEAGUE_ID)));
series1.setName(cursor.getString(cursor.getColumnIndex(Series.COLUMN_NAME)));
series1.setTimestamp(cursor.getString(cursor.getColumnIndex(Series.COLUMN_TIMESTAMP)));

series.add(series1);
} while (cursor.moveToNext());
}
db.close();
return series;
}

public int getSeriesCount() {
String countQuery = "SELECT * FROM " + Series.TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int count = cursor.getCount();
cursor.close();
return count;
}
public int updateSeries(Series series) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Series.COLUMN_NAME, series.getName());
return db.update(Series.TABLE_NAME, values, Series.COLUMN_ID + " = ?",
new String[]{String.valueOf(series.getId())});
}

public void deleteSeries(Series series) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(Series.TABLE_NAME, Series.COLUMN_ID + " = ?",
new String[]{String.valueOf(series.getId())});
db.close();
}

//Games Methods
public long insertGames(String games) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Games.COLUMN_SCORE, getGamesCount());
values.put(Games.COLUMN_STRIKES, getGamesCount());
values.put(Games.COLUMN_SPARES, getGamesCount());
values.put(Games.COLUMN_SPLITS, getGamesCount());
values.put(Games.COLUMN_SPLIT_CONVERSIONS, getGamesCount());
values.put(Games.COLUMN_OPEN_FRAMES, getGamesCount());
values.put(Games.COLUMN_TIMESTAMP, getGamesCount());
long id = db.insert(Games.TABLE_NAME, null, values);
db.close();
return id;
}
public Games getGames(long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(Games.TABLE_NAME,
new String[]{Games.COLUMN_ID, Games.COLUMN_LEAGUE_ID, Games.COLUMN_SCORE, Games.COLUMN_STRIKES, Games.COLUMN_SPARES, Games.COLUMN_SPLITS, Games.COLUMN_SPLIT_CONVERSIONS, Games.COLUMN_OPEN_FRAMES, Games.COLUMN_TIMESTAMP},
Series.COLUMN_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);

if (cursor != null)
cursor.moveToFirst();
Games games = new Games(
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_ID)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_LEAGUE_ID)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SCORE)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_STRIKES)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPARES)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPLITS)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPLIT_CONVERSIONS)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_OPEN_FRAMES)),
cursor.getString(cursor.getColumnIndex(Games.COLUMN_TIMESTAMP)),
cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPARES)));

cursor.close();
return games;
}

public List<Games> getAllGames() {
List<Games> games = new ArrayList<>();
String selectQuery = "SELECT * FROM " + Games.TABLE_NAME + " ORDER BY " +
Games.COLUMN_TIMESTAMP + " DESC";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
Games games1 = new Games();
games1.setId(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_ID)));
games1.setLeagueId(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_LEAGUE_ID)));
games1.setScore(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SCORE)));
games1.setStrikes(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_STRIKES)));
games1.setSpares(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPARES)));
games1.setSplits(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPLITS)));
games1.setSplitConversions(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_SPLIT_CONVERSIONS)));
games1.setOpenFrames(cursor.getInt(cursor.getColumnIndex(Games.COLUMN_OPEN_FRAMES)));

games1.setTimestamp(cursor.getString(cursor.getColumnIndex(Games.COLUMN_TIMESTAMP)));

                games.add(games1);
} while (cursor.moveToNext());
}
db.close();
return games;
}

public int getGamesCount() {
String countQuery = "SELECT * FROM " + Games.TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int count = cursor.getCount();
cursor.close();
return count;
}

public int updateGames(Games games) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Games.COLUMN_SCORE, games.getScore());
values.put(Games.COLUMN_STRIKES, games.getStrikes());
values.put(Games.COLUMN_SPARES, games.getSpares());
values.put(Games.COLUMN_SPLITS, games.getSplits());
values.put(Games.COLUMN_SPLIT_CONVERSIONS, games.getSplitConversions());
values.put(Games.COLUMN_OPEN_FRAMES, games.getOpenFrames());

return db.update(Games.TABLE_NAME, values, Games.COLUMN_ID + " = ?",
new String[]{String.valueOf(games.getId())});
}

public void deleteGames(Games games) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(Games.TABLE_NAME, Games.COLUMN_ID + " = ?",
new String[]{String.valueOf(games.getId())});
db.close();
}
}

数据库.Models.Games.java

public class Games {
public static final String TABLE_NAME = "Games";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_LEAGUE_ID = "league_id";
public static final String COLUMN_SCORE = "score";
public static final String COLUMN_STRIKES = "strikes";
public static final String COLUMN_SPARES = "spare";
public static final String COLUMN_OPEN_FRAMES = "openframes";
public static final String COLUMN_SPLITS = "plits";
public static final String COLUMN_SPLIT_CONVERSIONS = "splitconversions";
public static final String COLUMN_TIMESTAMP = "timestamp";
private int id;
private int league_id;
private int score;
private int strikes;
private int spares;
private int openframes;
private int splits;
private int splitconversions;
private String timestamp;
public static final String CREATE_TABLE =
"CREATE TABLE " + TABLE_NAME + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COLUMN_LEAGUE_ID + " INTEGER,"
+ COLUMN_SCORE + " INTEGER,"
+ COLUMN_STRIKES + " INTEGER,"
+ COLUMN_SPARES + " INTEGER,"
+ COLUMN_OPEN_FRAMES + " INTEGER,"
+ COLUMN_SPLITS + " INTEGER,"
+ COLUMN_SPLIT_CONVERSIONS + " INTEGER,"
+ COLUMN_TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP"
+ ")";
public Games(int anInt, int cursorInt, int i, int anInt1, int cursorInt1, int i1, int anInt2, int cursorInt2, String string, int i2) {
}
public Games() {
this.id = id;
this.league_id = league_id;
this.score = score;
this.strikes = strikes;
this.spares = spares;
this.openframes = openframes;
this.splits = splits;
this.splitconversions = splitconversions;
this.timestamp = timestamp;
}
public int getId() {
return id;
}
public int getLeagueId() { return league_id; }
public int getScore() { return score; }
public int getStrikes() { return strikes; }
public int getSpares() { return spares; }
public int getOpenFrames() { return openframes; }
public int getSplits() { return splits; }
public int getSplitConversions() { return splitconversions; }
public String getTimestamp() {
return timestamp;
}
public void setId(int id) {
this.id = id;
}
public void setLeagueId(int league_id) {
this.league_id = league_id;
}
public void setScore(int score) { this.score = score; }
public void setStrikes(int strikes) { this.strikes = strikes; }
public void setSpares(int spares) { this.spares = spares; }
public void setOpenFrames(int openframes) { this.openframes = openframes; }
public void setSplits(int splits) { this.splits = splits; }
public void setSplitConversions(int splitconversions) { this.splitconversions = splitconversions; }
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}

GamesActivity.java

    public class GamesActivity extends AppCompatActivity {
private GamesAdapter mAdapter;
private List<Games> gamesList = new ArrayList<>();
private CoordinatorLayout coordinatorLayout;
private RecyclerView recyclerView;
private TextView noGamesView;
private DatabaseHelper db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_games);
coordinatorLayout = findViewById(R.id.coordinator_layout);
recyclerView = findViewById(R.id.recycler_view);
noGamesView = findViewById(R.id.empty_games_view);
db = new DatabaseHelper(this);
gamesList.addAll(db.getAllGames());

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.add_games_fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showGamesDialog(false, null, -1);
}
});
mAdapter = new GamesAdapter(this, gamesList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
recyclerView.setAdapter(mAdapter);
toggleEmptyGames();
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, final int position) {
}
@Override
public void onLongClick(View view, int position) {
showActionsDialog(position);
}
}));
}

private void createGames(String games) {
long id = db.insertGames(games);
Games n = db.getGames(id);
if (n != null) {
gamesList.add(0, n);
mAdapter.notifyDataSetChanged();
toggleEmptyGames();
}
}
private void updateGames(int score, int strikes, int spares, int splits, int splitconversions, int openframes, int position, String timestamp) {
Games n = gamesList.get(position);
n.setScore(score);
n.setStrikes(strikes);
n.setSpares(spares);
n.setSplits(splits);
n.setSplitConversions(splitconversions);
n.setOpenFrames(openframes);
n.setTimestamp(timestamp);
db.updateGames(n);
gamesList.set(position, n);
mAdapter.notifyItemChanged(position);
toggleEmptyGames();
}
private void deleteGames(int position) {
db.deleteGames(gamesList.get(position));
gamesList.remove(position);
mAdapter.notifyItemRemoved(position);
toggleEmptyGames();
}
private void showActionsDialog(final int position) {
CharSequence colors[] = new CharSequence[]{"Edit", "Delete"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose option");
builder.setItems(colors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
showGamesDialog(true, gamesList.get(position), position);
} else {
deleteGames(position);
}
}
});
builder.show();
}

private void showGamesDialog(final boolean shouldUpdate, final Games games, final int position) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
View view = layoutInflaterAndroid.inflate(R.layout.dialog_game, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(GamesActivity.this);
alertDialogBuilderUserInput.setView(view);
final EditText inputScore = view.findViewById(R.id.etScore);
final EditText inputStrikes = view.findViewById(R.id.etStrikes);
final EditText inputSpares = view.findViewById(R.id.etSpares);
final EditText inputSplits = view.findViewById(R.id.etSplits);
final EditText inputSplitConversions = view.findViewById(R.id.etSplitConversions);
final EditText inputOpenFrames = view.findViewById(R.id.etOpenFrames);
TextView dialogTitle = view.findViewById(R.id.dialog_title);
dialogTitle.setText(!shouldUpdate ? "Enter Game Stats" : "Edit Game Stats");
if (shouldUpdate && games != null) {
inputScore.setText(games.getScore());
inputStrikes.setText(games.getStrikes());
inputSpares.setText(games.getSpares());
inputSplits.setText(games.getSplits());
inputSplitConversions.setText(games.getSplitConversions());
inputOpenFrames.setText(games.getOpenFrames());
}
alertDialogBuilderUserInput
.setCancelable(false)
.setPositiveButton(shouldUpdate ? "update" : "save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBox, int id) {
}
})
.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBox, int id) {
dialogBox.cancel();
}
});

final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.show();

alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (shouldUpdate && games != null) {

updateGames(inputScore.getText().toString(), position);
updateGames(inputStrikes.getText().toString(), position);
updateGames(inputSpares.getText().toString(), position);
updateGames(inputSplits.getText().toString(), position);
updateGames(inputSplitConversions.getText().toString(), position);
updateGames(inputOpenFrames.getText().toString(), position);

} else {
createGames(inputScore.getText().toString());
createGames(inputStrikes.getText().toString());
createGames(inputSpares.getText().toString());
createGames(inputSplits.getText().toString());
createGames(inputSplitConversions.getText().toString());
createGames(inputOpenFrames.getText().toString());
}
}
});
}
private void toggleEmptyGames() {
if (db.getGamesCount() > 0) {
noGamesView.setVisibility(View.GONE);
} else {
noGamesView.setVisibility(View.VISIBLE);
}
}
}

如果您需要任何进一步的帮助,请告诉我。

最佳答案

我看起来你应该更换:-

        updateGames(inputScore.getText().toString(), position);
updateGames(inputStrikes.getText().toString(), position);
updateGames(inputSpares.getText().toString(), position);
updateGames(inputSplits.getText().toString(), position);
updateGames(inputSplitConversions.getText().toString(), position);
updateGames(inputOpenFrames.getText().toString(), position);

与:-

        updateGames(
Integer.parseInt(inputScore.getText().toString()),
Integer.parseInt(inputScore.getText().toString()),
Integer.parseInt(inputSpares.getText().toString()),
Integer.parseInt(inputSplits.getText().toString()),
Integer.parseInt(inputSplitConversions.getText().toString()),
Integer.parseInt(inputOpenFrames.getText().toString()),
position,
String.valueOf(System.currentTimeMillis()) //<<<<< FORMAT GUESSED
);

这将适合 updateGames 方法的签名,即:-

    private void updateGames(
int score,
int strikes,
int spares,
int splits,
int splitconversions,
int openframes,
int position,
String timestamp) {

Games n = gamesList.get(position);
n.setScore(score);
n.setStrikes(strikes);
n.setSpares(spares);
n.setSplits(splits);
n.setSplitConversions(splitconversions);
n.setOpenFrames(openframes);
n.setTimestamp(timestamp);
db.updateGames(n);
gamesList.set(position, n);
mAdapter.notifyItemChanged(position);
toggleEmptyGames();
}
  • 它使用db.updateGames(n);来更新数据库。

  • 如果 EditText 中的值不正确(例如它们必须仅为数字),那么您将收到解析异常。

  • 注意您可能需要调整时间戳的格式以适应。

  • 此外这是原则上的代码,尚未经过测试。

关于java - 方法 updateGames 类中的 GamesActivity 不能为 App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50418023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com