【问题标题】:Shuffle the id of table to get details in android打乱表的 id 以获取 android 中的详细信息
【发布时间】:2011-12-11 12:34:39
【问题描述】:

我有 student 表,它有四个字段 id、name、address 和 age。在这个表 50 学生。我的问题是,如何改组 id 并获取该 id 的详细信息(id、姓名、地址和年龄)并一次获取一个 id,如果我单击 next 按钮然后是下一个学生详细信息。

DatabaseHeper.java

 // I donot understand which code write in DatabaseHeper.java file 
 /*
public Cursor shuffleJokes(int [] id) {

        Cursor c = null;
    c = myDataBase.rawQuery("select _id,title,body from jokes where title ="
            + id, null);
    return c;
}*/

public void shuffleJokes(int [] ar) {       

Random rnd = new Random();
for (int i = ar.length - 1; i >= 0; i--)
{
  int index = rnd.nextInt(i + 1);
  // Simple swap
  int a = ar[index];
  ar[index] = ar[i];
  ar[i] = a;
}

shuffleStudnt.java

DatabaseHelper db;
Cursor cur
cur=db.shuffleArray(arrayofid);  // how to get arrayofid array which is id of student table
cur.moveToFirst();    

我有问题,如何在数组中获取表 ID。请给我写在 DatabaseHeper.java 和 shuffleStudent.java 文件中的代码的最佳解决方案。

【问题讨论】:

    标签: android database shuffle


    【解决方案1】:

    我认为您每次点击按钮时都想从表格中随机选择一个学生,对吧?

    然后我会查询所有学生,将他们保存到一个数组中,然后每次用户点击按钮时从该数组中随机选择一个。

    【讨论】:

    • 我知道,但是如何将所有学生保存为数组?
    • 创建一个包含 id、name、address 和 age 字段的“Student”类,为数据库中的每个条目创建一个“Student”,然后将它们保存到 ArrayList
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    • 2012-02-21
    • 1970-01-01
    • 2018-07-31
    相关资源
    最近更新 更多