如何突出显示列表视图中的多个字符

时间:2011-05-05 03:30:54

标签: android listview

您好我目前有一个列表视图,需要将字符串中某个计算位置的字符更改为其他颜色。例如。我想要这样的东西:

  

Randomstuffhere 2011/4/4 05:44 2011/4/4 05:44

     

Randomstuff 2011/4/4 05:43 2011/4/4 05:44

     

Somethingelse 2011/4/4 05:41 2011/4/4 05:44

出现在列表视图中

有点像在普通文本视图上使用SpannableString但数组不接受Spannable字符串对象。这是我现在拥有的。 generatetring()方法将更新字段temphistoricweekdata。

private void populatearray() {
        try
        {   
            results.clear();
            historicweek = getListView();
            db = openOrCreateDatabase(DB_NAME, SQLiteDatabase.CREATE_IF_NECESSARY, null);
            Cursor timesheetCursor = db.rawQuery("SELECT id, starttime, endtime, starttime1,endtime1 FROM timesheet WHERE year = (SELECT MAX(year) FROM timesheet) and week =(SELECT MAX(week) FROM timesheet where year = (SELECT MAX(year) FROM timesheet ));", null);

            timesheetCursor.moveToFirst();

            while (!timesheetCursor.isAfterLast()){

                int iddata = timesheetCursor.getInt(0);
                idArrayHistoric.add(iddata);
                DateAA = timesheetCursor.getString(1);
                DateBB = timesheetCursor.getString(2);
                DateCC = timesheetCursor.getString(3);
                DateDD = timesheetCursor.getString(4);


                generatestring();

                results.add(temphistoricweekdata);
                timesheetCursor.moveToNext();
            }
            timesheetCursor.close();
            db.close();
        historyadapter = new ArrayAdapter<String>(this, R.layout.list_white_text,R.id.list_content,results);
        this.setListAdapter(historyadapter);
        }

        catch (SQLiteException se)
        {
        }

        }

1 个答案:

答案 0 :(得分:1)

只需使用自定义适配器并根据需要设置布局