洗牌表的ID来获得在Android的细节 [英] Shuffle the id of table to get details in android
问题描述
我的学生表,其中有四个fiels 的ID,姓名,地址和年龄。在该表50的学生。我的问题是,如何洗牌ID并获得该ID的详细信息(ID,姓名,地址,年龄),并在同一时间获得一个ID,如果我点击下一步按钮,然后在下一个学生的详细信息。
I have student table , which has four fiels id, name, address and age. In this table 50 student. My question is , How to shuffle the id and get that id's details( id, name, address and age) and get the one id at a time and if i click the next button then next student details.
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阵列。请给我这美元C $ C写的最好的解决方案的 DatabaseHeper.java 和 shuffleStudent.java 文件。
推荐答案
我想你想你每次点击一个按钮,时间从表中选择一个随机的学生,对吧?
I think you want to select a random student from the table every time you tap a button, right?
然后我会查询所有的学生,将它们保存到一个数组,然后从数组每次用户点击该按钮选择一个随机。
Then I would query all students, save them to an array and then select one randomly from that array everytime the user taps the button.
这篇关于洗牌表的ID来获得在Android的细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!