我是 android 和 Java 世界的新手,我想在显示之前编辑光标数据结果。为此,我编写了以下代码
private static final String[] INTERNAL_COLUMNS_1 = new String[] {
MediaStore.Audio.Media._ID,MediaStore.Audio.Media.TITLE};
private static final String[] INTERNAL_COLUMNS_2 = new String[] {
MediaStore.Audio.Media._ID, "fixString(" + MediaStore.Audio.Media.TITLE + ")"};
private Cursor getInternals() {
return query(
MediaStore.Audio.Media.INTERNAL_CONTENT_URI, INTERNAL_COLUMNS_1,
constructBooleanTrueWhereClause(mFilterColumns),
null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
private Cursor mCursor = new SortCursor(getInternals());
public String fixString(String oldstr)
{
String str = new String(oldstr);
str = str.replace("_", " ");
if (Character.isLowerCase(str.charAt(0)))
{
str = str.substring(0,1).toUpperCase() + str.substring(1,str.length());
}
for(int i=1;i<str.length();i++)
{
if ((Character.isUpperCase(str.charAt(i)))
&& (Character.isLetter(str.charAt(i)))
&& (Character.isLowerCase(str.charAt(i - 1)))
&& (Character.isLetter(str.charAt(i - 1))))
{
str = str.substring(0,i) + " " + str.substring(i,str.length());
}
}
return str;
}
public static void main(){
for (int i = 0; i < mCursor.getCount(); i++)
{
mCursor.moveToPosition(i);
String string = mCursor.getString(1);
Log.d("OUT"," string = "+ string);
}
使用INTERNAL_COLUMNS_1,日志显示
TomSkinner
Jack_Smith
foxRayan
我想要作为光标结果:
Tom Skinner
Jack Smith
Fox Rayan
所以我使用了INTERNAL_COLUMNS_2,但我有例外
android.database.sqlite.SQLiteException: no such function: fixString
有谁知道该怎么做,或任何其他想法?