gpt4 book ai didi

java - 如何按下一个按钮,移动到数组的下一个位置

转载 作者:行者123 更新时间:2023-11-30 01:42:19 24 4
gpt4 key购买 nike

我开始在 android 中编程,但我遇到了困难。我正在填充一个 ArrayList 来寻找数据库对象。

 public ArrayList<Box> seekBoxPerLine() {
boxes = new ArrayList<Box>();
Cursor cursor;
if (init == 0) {
String sql = "SELECT * FROM Boxe WHERE line='" + numberLine+ "' ORDER BY position ASC; ";
cursor = database.rawQuery(sql, null);
} else {
String sql = "SELECT * FROM Box WHERE line='" + numberLine + "' ORDER BY positio DESC; ";
cursor = database.rawQuery(sql, null);
}
if (cursor.getCount() >= 0) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Box box = new Box();

box.setId(cursor.getLong(0));
box.setFase_cultivo(cursor.getString(1));
boxes.add(box);
cursor.moveToNext();
}
}
cursor.close();
return boxes;
}

我进行验证,并将对象的 ID 传递给 EditText:

  public void verifyBoxLine() {
if (numberLine != null) {
boxes = seekBoxPerLine();
for (Box boxesPerLine : boxes) {
etNumberBoxActually.setText(String.valueOf(boxesPerLine.getId()));

break;
}
}
}

现在我的疑问是如何对按钮进行编程以按下它以增加相同的 EditText 和下一个 arrayList ID?我不知道欢迎任何帮助。

我的 onClick 按钮:

  public void onClick(View view) {
if (view == btNextBox) {


}

注意:这些框按顺序排成一行,我可以选择从行的开头或结尾开始,所以我意识到检查,不知道它有多大帮助,但它会让它更清楚.

最佳答案

为什么不使用内部计数器?

每当您从数据库查询时,您都会将计数器重置为 0;

每当您点击按钮时,您就会增加计数器...

private int indexPos = 0;

public ArrayList<Box> seekBoxPerLine() {
//... as above
indexPos = 0;
}

public void onClick(View view) {
if (view == btNextBox) {
indexPos = indexPos + 1;
//... do whatever you need to do
}
}

关于java - 如何按下一个按钮,移动到数组的下一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311597/

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