как изменить содержимое строки из метода onclick - PullRequest
0 голосов
/ 13 ноября 2011

У меня сложный макет строки ("2 imageViews, 3 TextViews"), поэтому я определил свой собственный адаптер.Я хочу изменить цвет для textViews одним щелчком мыши!и я столкнулся с проблемой не финальной переменной, на которую ссылаются изнутри внутреннего класса, есть ли какой-нибудь поворот вокруг этой проблемы?

public View getView(final int position, View convertView, ViewGroup parent) {

    ViewHolder holder = new ViewHolder();

    if(convertView==null)
    {     minflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = minflater.inflate(R.layout.list_item2, null);


    holder.title = (TextView) convertView.findViewById(R.id.rowtext1);
    holder.note = (TextView) convertView.findViewById(R.id.rowtext2);
    holder.date = (TextView) convertView.findViewById(R.id.rowtext3);
    holder.course= (TextView) convertView.findViewById(R.id.rowtext4);
    holder.icon = (ImageView) convertView.findViewById(R.id.rowimage1);
    holder.read = (ImageView) convertView.findViewById(R.id.rowimage2);


    convertView.setOnClickListener(new OnClickListener() {
        private int pos = position;

        @Override
        public void onClick(View v) {
            numberOfClicks++;
                            // Heres the problem 
            holder.title.setTextColor();
            if(pos==0 &&  numberOfClicks % 2 ==1 )
                v.setBackgroundResource(R.drawable.stoprow);
            else if  (pos==0 &&  numberOfClicks % 2 !=1 )
                v.setBackgroundResource(R.drawable.toprow);


            else if (pos==getCount()-1 &&  numberOfClicks % 2 !=1 )
                v.setBackgroundResource(R.drawable.bottomrow);
            else
                v.setBackgroundResource(R.drawable.smiddlerow);
        }
        });





        convertView.setTag(holder);
        } else {
        // Get the ViewHolder back to get fast access to the TextView
        // and the ImageView.
        holder = (ViewHolder) convertView.getTag();
        }

1 Ответ

0 голосов
/ 14 ноября 2011

У меня тоже возникла такая же проблема, и, наконец, я получил решение следующим образом

 final TextView tempView = holder.title;

, чем в onclick:

  title.setTextColor();

См. Эту ссылку для дальнейшей ссылки Просмотр изображения в Listviewне может измениться во время выполнения в Android

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...