Android列表视图中的颜色映射错误

时间:2018-11-06 11:02:04

标签: android

这是我的代码。...

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            //View view =super.getView(position, convertView, parent);

            View view = convertView;
            if(view == null){
                view = LayoutInflater.from(mContext).inflate(R.layout.list_adv_item,parent,false);
            }

            Advertisement currAdv = advList.get(position);
            TextView date = (TextView)view.findViewById(R.id.textView_date);
            date.setText(currAdv.getmDate());
            date.setTextColor(Color.WHITE);



            TextView name = (TextView) view.findViewById(R.id.textView_amount);
            name.setText(currAdv.getmAmount() + " at");


            TextView price = (TextView) view.findViewById(R.id.textView_price);
            price.setText(currAdv.getmPrice());



            TextView type = (TextView) view.findViewById(R.id.textView_type);

            if (type.getText().equals("Sell")) {
                type.setTextColor(Color.RED);
            } else {
                type.setTextColor(Color.parseColor("#00FF00"));
            }

            type.setText(currAdv.getmType());


            return view;
        }

2 个答案:

答案 0 :(得分:0)

如我所见,您正在访问setText()方法之前的editText值。也许这就是您想要的:

highscore

希望有帮助。

答案 1 :(得分:0)

您的问题尚不清楚。如果要根据广告类型设置字体颜色,则必须在if控件中使用它的类型。不使用textview值。

TextView type = (TextView) view.findViewById(R.id.textView_type);

if (currAdv.getmType().equals("Sell")) {
    type.setTextColor(Color.RED);
} else {
    type.setTextColor(Color.parseColor("#00FF00"));
}
type.setText(currAdv.getmType());