使用textview显示sql android的分数

时间:2014-09-04 17:12:27

标签: android sql textview

好的,所以我试图为我的应用程序制作高分,我不知道如何制作包含日期,分数和名称的字符串(它们已经在sql中,现在我需要将它们拉出来)出现在textview中

    public String[] getAllScores(){

        String selectQuery = "SELECT  * FROM " + TABLE_SCORE + "LIMIT 10";



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

        int i = 0;

        String[] data = new String[cursor.getCount()];

        while (cursor.moveToNext()) {

            data[i] = cursor.getString(1);

            i = i++;

        }
        cursor.close();
        hs.close();
        // return score array
        return data;
    }

}

显示得分的活动

Highscore hs=new Highscore(this);
     hs.addScore(name, currentDTS, scukupno);
     hs.getAllScores();
     TextView score1=(TextView) findViewById(R.id.Rezultat);
     score1.setText( What to write here???? );

2 个答案:

答案 0 :(得分:0)

如果需要,您应该在 score1 中打印所有内容。

您可以使用:

String[] stringArray = hs.getAllScores();
String tempString = "";
    for(String string:stringArray){
tempString = tempString+string;//this will give you a string with all string
    }
score1.setText(tempString);//this will set the textView with everything

但是你可能想要在它们之间留一个空格或破折号或任何东西以使它清楚。

只需在tempString = tempString + "-";

之后加tempString = tempString+string;

答案 1 :(得分:0)

您尝试使用TextUtils.join吗? http://developer.android.com/reference/android/text/TextUtils.html#join%28java.lang.CharSequence,%20java.lang.Iterable%29

String[] stringArray = hs.getAllScores();
score1.setText(TextUtils.join("-", stringArray));

替换" - "无论你想用什么。