【问题标题】:How working system in getView in Android?Android中getView的工作系统如何?
【发布时间】:2015-02-26 14:34:03
【问题描述】:
@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 上改变颜色。我做错了什么?好像没问题

【问题讨论】:

    标签: android android-layout android-activity view baseadapter


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 1970-01-01
      • 2012-06-02
      • 2010-11-26
      • 1970-01-01
      • 2010-11-18
      • 2011-09-08
      • 1970-01-01
      • 2018-09-03
      相关资源
      最近更新 更多