Android 中的 getView 如何工作?

How working system in getView in Android?

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = layoutInflater.inflate(R.layout.statistics_adapter, parent, false);
        }

        textViewLeft= (TextView) view.findViewById(R.id.textView);
        textViewRight= (TextView) view.findViewById(R.id.textView2);
        imageView= (ImageView) view.findViewById(R.id.imageView);

        textViewLeft.setText(title[position]);
        textViewRight.setText(str[position]);

        imageView.setVisibility(View.GONE);

        if(position==(0)||position==(1)||position==(2)||position==(5)){
            imageView.setVisibility(View.VISIBLE);
            if (textViewRight.getText().equals("ok")) imageView.setImageResource(R.drawable.ok);
            if (textViewRight.getText().equals("error")) imageView.setImageResource(R.drawable.error);
            textViewRight.setText("");
        }

        if (position==8){
            textViewRight.setTextColor(Color.parseColor("#ff0000"));
        }
        if (position>10){
            textViewLeft.setText("");
        }

        return view;
    }

在我的列表中,当您第一次向下滚动时,第 8 位的文本变为红色。如果您上下滚动 listView 5 次,那么我的文本将在 #ff0000 上改变颜色。我做错了什么?好像还行

我想如果它不在位置 8,你想将颜色设置为黑色。

if (position==8){
        textViewRight.setTextColor(Color.parseColor("#ff0000"));
}
else {
       textViewRight.setTextColor(Color.parseColor("#ffffff"));
}