0

当我单击列表视图中的一行时,holder.four 变得可见,然后当我第二次单击时它变得不可见。当我第三次单击以使其可见时,它不起作用。我认为 vi onclick 侦听器中的可运行线程存在问题。有人可以告诉我如何解决这个问题。

***vi = inflater.inflate(R.layout.row_operation, null);
    holder = new ViewHolder();
    holder.one = (TextView) vi.findViewById(R.id.text_on);
    holder.two = (TextView) vi.findViewById(R.id.text_messag);
    holder.three = (TextView) vi.findViewById(R.id.text_th);
    holder.four = (TextView) vi.findViewById(R.id.text_details);
    vi.setTag(holder);
    holder.one.setText(data.get(position).getmontant()+" EUR");
    holder.two.setText((data.get(position).getlibelle()));
    holder.three.setText(data.get(position).getdateValeur());
    holder.four.setVisibility(View.GONE);
    holder.four.setText(data.get(position).getdateOper());
    //clickEvent();
    vi.setOnClickListener(this);
    return vi;
}
/*
 * On Click event
 */
@Override
public void onClick(final View v){
    v.post(new Runnable() {
        @Override
        public void run() {
            ViewHolder holder = ((ViewHolder)v.getTag());
            holder.four.setVisibility(View.VISIBLE);
            if(selectedHolder != null)
                holder.four.setVisibility(View.GONE);
            selectedHolder = holder;
        }
    });
}

} *

4

2 回答 2

1

我想'if condition这是你的逻辑中断的地方 -

您需要将 selectedHolder 重置为null您的逻辑才能正常工作 -

而不是这个 -

if(selectedHolder != null)
                holder.four.setVisibility(View.GONE);
            selectedHolder = holder;

做这个 -

if(selectedHolder != null) {
 holder.four.setVisibility(View.GONE);
 selectedHolder = null;
} else {
 selectedHolder = holder;
}
于 2013-10-22T06:05:23.553 回答
1
check this piece of code

@Override
public void onClick(final View v){
    v.post(new Runnable() {
        @Override
        public void run() {
            ViewHolder holder = ((ViewHolder)v.getTag());

            if(selectedHolder != null)
        {
            if (holder.four.getVisibility()==View.GONE)
               holder.four.setVisibility(View.VISIBLE);
            else if (holder.four.getVisibility()==View.INVISIBLE)
               holder.four.setVisibility(View.VISIBLE);
            else if (holder.four.getVisibility()==View.VISIBLE)           
                       holder.four.setVisibility(View.GONE);
        }
            selectedHolder = holder;
        }
    });
}
于 2013-10-22T06:12:35.507 回答