android-ListView行中的ViewFlipper
作者:互联网
我有一个ListView,其中每个行都有一个XML视图.
每行上都有一个ViewFlipper和一个Button,其目的是按下该按钮并翻转ViewFlipper上的视图.
问题是我无法获取Button来翻转正确的ViewFlipper.我在ListView适配器中设置行,因此我假设这是我应该处理按钮单击的地方.
尽管正在处理单击,但是被“翻转”的ViewFlipper在另一行上.我认为这是因为适配器正在回收视图-我只是无法解决该问题.
我的代码是
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mLayoutInflater.inflate(mLayout, null);
viewHolder = new ViewHolder();
viewHolder.flipper = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);
viewHolder.v2FieldName = (TextView) convertView.findViewById(R.id.tvLongName);
viewHolder.button01 = (ImageButton) convertView.findViewById(R.id.imageButton1);
viewHolder.button01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
viewHolder.flipper.showNext();
}
});
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.v2FieldName.setText(items.get(position).get("name"));
return convertView;
}
任何帮助表示赞赏
解决方法:
设法使其现在工作,代码是
public View getView(int position, View convertView, ViewGroup parent) {
final ViewFlipper flipperTemp;
if (convertView == null) {
convertView = mLayoutInflater.inflate(mLayout, null);
viewHolder = new ViewHolder();
viewHolder.flipper = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);
viewHolder.flipper.setDisplayedChild(0);
viewHolder.v2FieldName = (TextView) convertView.findViewById(R.id.tvLongName);
viewHolder.button01 = (ImageButton) convertView.findViewById(R.id.imageButton1);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
viewHolder.flipper.setDisplayedChild(0);
}
flipperTemp = (ViewFlipper) convertView.findViewById(R.id.viewConfFlipper1);
viewHolder.v2FieldName.setText(items.get(position).get("name"));
viewHolder.button01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
flipperTemp.showNext();
}
});
return convertView;
}
标签:viewflipper,android,android-listview 来源: https://codeday.me/bug/20191009/1880507.html