2
我將視圖翻轉器視爲列表視圖項目,並在運行時將項目加載到視圖翻轉器。在列表視圖中維護視圖翻轉器的狀態
問題:我的問題是當我將視圖翻轉到特定的行時,並且當我滾動列表視圖時,在翻轉到右側後被設置到特定位置的視圖丟失。
在滾動所有行中的視圖鰭狀肢時重新初始化爲第0狀態。
這裏是我的底座適配器:
public class ListViewAdapter extends BaseAdapter {
private Context context;
private ArrayList<TypeOneDataClass> typeOneList;
private LayoutInflater inflater;
public static ArrayList<ViewPager> myPagers = new ArrayList<ViewPager>();
private ArrayList<Integer> myInnerList;
//public static ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>();
private ArrayList<FlipperPosition> myFlipList = new ArrayList<FlipperPosition>();
public ListViewAdapter(Context context,
ArrayList<TypeOneDataClass> typeOneList) {
this.context = context;
this.typeOneList = typeOneList;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return typeOneList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return typeOneList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return IGNORE_ITEM_VIEW_TYPE;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
FlipperPosition flipperPosition;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_item, null, false);
holder.viewFlipper = (ViewFlipper)convertView.findViewById(R.id.myFlipper);
for(int i=0;i<typeOneList.get(position).getDetailsList().size();i++){
View v = inflater.inflate(R.layout.pager_item, null);
holder.viewFlipper.addView(v);
final TextView tv_name = (TextView)v.findViewById(R.id.tv_name);
final TextView tv_fathersName = (TextView)v.findViewById(R.id.tv_fathersname);
Button btn_right = (Button)v.findViewById(R.id.btn_right);
Button btn_left = (Button)v.findViewById(R.id.btn_left);
final ViewHolder vHolder = holder;
btn_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
vHolder.viewFlipper.setInAnimation(context, R.anim.slide_in_left);
vHolder.viewFlipper.setOutAnimation(context, R.anim.slide_out_right);
vHolder.viewFlipper.showPrevious();
Toast.makeText(context, "Row"+position+" "+vHolder.viewFlipper.indexOfChild(vHolder.viewFlipper.getCurrentView()), 0).show();
}
});
btn_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
vHolder.viewFlipper.setInAnimation(context, R.anim.slide_in_right);
vHolder.viewFlipper.setOutAnimation(context, R.anim.slide_out_left);
vHolder.viewFlipper.showNext();
int indexofFliper = vHolder.viewFlipper.indexOfChild(vHolder.viewFlipper.getCurrentView());
Toast.makeText(context, "Row"+position+" "+indexofFliper, 0).show();
}
});
tv_name.setText(typeOneList.get(position).getName());
tv_fathersName.setText(typeOneList.get(position).getDetailsList().get(myFlipList.get(position).getFlipTermSet()).getFathersname());
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
class ViewHolder {
ViewFlipper viewFlipper;
}
謝謝@j__m,尋求幫助。爲我工作就像一個魅力。 –