0

我对 Android 很陌生,我想在 Listview 中更改 TextView 的文本颜色。尝试这个时,颜色不会改变。谁能帮我解决这个(简单的?)问题?

我在“BaseAdapter”中使用以下代码来控制 ListView:

    public View getView(int i, View view, ViewGroup viewGroup) {


    if (view == null) {
        view = mInflater.inflate(R.layout.cijfer_listitem, null);

        holder = new ViewHolder();
        holder.mCijferTxt = (TextView) view.findViewById(R.id.cijferTxt);
        holder.mVakTxt = (TextView) view.findViewById(R.id.vakTxt);
        holder.mVakUitgebreidTxt = (TextView) view.findViewById(R.id.vakUitgebreidTxt);
        holder.mIdTxt = (TextView) view.findViewById(R.id.idTxt);

        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();

    }

    Cijfer cijfer = mCijfers.get(i);

    holder.mCijferTxt.setText(cijfer.getCijfer());
    holder.mVakTxt.setText(cijfer.getCursus());
    holder.mVakUitgebreidTxt.setText(cijfer.getCursusUitgebreid());
    holder.mIdTxt.setText("" + cijfer.getCijferID());

    if (cijfer.isDef() == true ){

        holder.mCijferTxt.setTextColor(R.color.colorTxtDef);
    }
    else{
        holder.mCijferTxt.setTextColor((R.color.colorTxtConcept));
    }

    return view;
}

public class ViewHolder {
    public TextView mCijferTxt;
    public TextView mVakTxt;
    public TextView mVakUitgebreidTxt;
    public TextView mIdTxt;
}

我想更改 TextView“cijferTxt”的颜色。

希望这是足够的信息来帮助我:)

4

2 回答 2

2

试试这个

 holder.setTextColor(view.getResources().getColor(R.color.colorTxtDef));
于 2013-09-06T18:46:13.087 回答
0

您正在尝试将文本颜色设置为颜色资源 ID(这只是一个指向颜色的 ID)。您需要从此颜色资源 ID 中提取颜色。例子:

int color = context.getResources().getColor(R.color.colorTxtDef);
holder.mCijferTxt.setTextColor(color);
于 2013-09-06T18:31:04.670 回答