当我的listview被填充时,holder.four引用的TextView是可见的。当我选择一个行元素时,我希望holder.four对于所选行变得可见,但是当我选择另一行时,我希望先前的holder.four可见变为不可见,并且新选择的位置行holder.four变为可见。我怎样才能做到这一点。这是填充列表视图的getview方法。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
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);
} else
holder = (ViewHolder) vi.getTag();
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();
return vi;
}
答案 0 :(得分:3)
你去:
Holder selectedHolder;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
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);
} else
holder = (ViewHolder) vi.getTag();
//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);
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.setTag(holder);
vi.setOnClickListener(this);
return vi;
}
@Overrite
public void onClick(View v){
v.post(new Runnable() {
@Override
public void run() {
ViewHolder holder = ((ViewHolder)v.getTag());
holder.four.setVisibility(View.VISIABLE);
if(selectedHolder != null)
selectedHolder.four.setVisibility(View.INVISABLE);
selectedHolder = holder;
}
});
}
答案 1 :(得分:0)
检查我对此问题的回答:how can i get android list view selector items to remember their state off screen?
我认为你可能会使用类似的想法:扩展项目的布局。完成后,您还可以创建自定义事件并将其捕获到您需要的位置。