如图所示,1为在单词在数据库中的序号,按下ok会出现缺少3个字母的单词,缺少的字母的位置由随机数产生。请问各位大神,如何才能将缺少的字母正确的传给下面的选项中。
本人的代码如下,但是运行失败。
public void query(){
stuDB = SQLiteDatabase.openOrCreateDatabase("data/data/com.example.liuqianyu.databasetest/Word.s3db",null);
try{
String string = sno.getText().toString();
String sql = "select word from Vocabulary where no = "+string;
Cursor cursor = stuDB.rawQuery(sql,null);
cursor.moveToFirst();
word = cursor.getString(cursor.getColumnIndex("word"));
length =word.length()+"" ;
char[] word2;
word2= word.toCharArray();
if(word.length()>5){
words[boxPos[0]].setText(word2[pos1]);
words[boxPos[1]].setText(word2[pos2]);
words[boxPos[2]].setText(word2[pos3]);
word2[pos1]=blank;
word2[pos2]=blank;
word2[pos3]=blank;
}else{
// words[boxPos[0]].setText(word2[pos1]);
// words[boxPos[1]].setText(word2[pos2]);
word2[pos1]=blank;
word2[pos2]=blank;
}
String word3;
word3 = new String(word2);
sname.setText(word3);
text.setText(length);
}catch(Exception e){
Toast.makeText(this,"Check",Toast.LENGTH_LONG).show();
}
}
boxPos[] 是产生随机空缺位置的数组
words[] 是由5个textView组成的数组,个人感觉问题就出在这里,注释掉setText那几行可以正确运行,加上就直接执行catch了。
菜鸟求大神指点~