在第三个项目单击android后,Listview项目不可见

时间:2013-10-22 05:55:21

标签: android android-listview android-adapter

当我点击listview中的一行时,holder.four变得可见,然后当我第二次点击时它变得不可见。当我第三次点击使其可见时它不起作用。我相信它在vi onclick监听器中的runnable线程有问题。有人可以告诉我如何解决这个问题。

***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;
        }
    });
}

} *

2 个答案:

答案 0 :(得分:1)

我猜'if condition是逻辑中断的地方 -

你需要将所选文件夹重置回null以使你的逻辑工作 -

而不是这个 -

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

这样做 -

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

答案 1 :(得分: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;
        }
    });
}