2014-09-04 69 views
1

我使用This Tutorial使我的Custome Expandable列表視圖和我需要設置動畫項目,當有人點擊它的父母。 (只是我點擊的組必須有動畫) 我搜索並找出我也可以使用這種方法做到這一點。我如何設置自定義ExpandableListview上的每個項目的動畫

public void onGroupCollapse(int groupPosition) 

,但我不知道怎麼去查看我的孩子的,並設置動畫,它:(

這是我的動畫代碼:

Animation animation = AnimationUtils.loadAnimation(childsanimationview.getContext(), R.anim.fadein); 
      childsanimationview.setAnimation(animation); 

這是我的適配器代碼

public class MyExpandableListAdapter extends BaseExpandableListAdapter { 

private ArrayList<Parent> parents; 
private LayoutInflater inflater; 

// public View childsanimationview ; 
public MyExpandableListAdapter(Context c, ArrayList<Parent> parentsfrom) { 
    // Create Layout Inflator 
    parents = parentsfrom; 
    // childsanimationview=childsanimation; 
    inflater = LayoutInflater.from(c); 
} 

//這個函數用於膨脹父行查看

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parentView) { 

    final Parent parent = parents.get(groupPosition); 

    // Inflate grouprow.xml file for parent rows 
    convertView = inflater.inflate(R.layout.grouprow, parentView, false); 
    // Get grouprow.xml file elements and set values 
    ((TextView) convertView.findViewById(R.id.parent_name)).setText(parent.getParentName()); 
    ImageView parent_right_img = (ImageView) convertView.findViewById(R.id.parent_right_img); 
    ImageView parent_left_img = (ImageView) convertView.findViewById(R.id.parent_left_img); 

    // Change right && left arrow image on parent at runtime 
    if (isExpanded == true) { 
     parent_right_img.setImageResource(R.drawable.parent_opened); 
     parent_left_img.setImageResource(R.drawable.parent_opened); 
    } else { 
     parent_right_img.setImageResource(R.drawable.parent_right_closed); 
     parent_left_img.setImageResource(R.drawable.parent_left_closed); 
    } 
    //  checkbox.setOnCheckedChangeListener(new CheckUpdateListener(parent)); 

    return convertView; 
} 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parentView) { 

    final Parent parent = parents.get(groupPosition); 
    final Child child = parent.getChildren().get(childPosition); 

    // Inflate childrow.xml file for child rows 
    convertView = inflater.inflate(R.layout.childrow, parentView, false); 

    TextView Product_Name = (TextView) convertView.findViewById(R.id.product_name); 
    TextView Ingredient = (TextView) convertView.findViewById(R.id.ingredient); 
    TextView Product_Price = (TextView) convertView.findViewById(R.id.product_price); 
    ImageView Product_Image = (ImageView) convertView.findViewById(R.id.product_img); 


    Product_Name.setText(child.getProductName()); 
    Ingredient.setText(child.getIngredient()); 
    Product_Price.setText(child.getProductPrice()); 
    Product_Image.setImageResource(child.getProductImg()); 

    // Product_Image.setImageResource(getResources().getIdentifier("com.androidexample.customexpandablelist:drawable/setting" + parent.getParentName(), null, null)); 

    return convertView; 
} 


@Override 
public Object getChild(int groupPosition, int childPosition) { 
    return parents.get(groupPosition).getChildren().get(childPosition); 
} 

//Call when child row clicked 
@Override 
public long getChildId(int groupPosition, int childPosition) { 
    /****** When Child row clicked then this function call *******/ 
    return childPosition; 
} 

@Override 
public int getChildrenCount(int groupPosition) { 
    int size = 0; 
    if (parents.get(groupPosition).getChildren() != null) 
     size = parents.get(groupPosition).getChildren().size(); 
    return size; 
} 

@Override 
public Object getGroup(int groupPosition) { 
    return parents.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
    return parents.size(); 
} 

//Call when parent row clicked 
@Override 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 

@Override 
public void notifyDataSetChanged() { 
    // Refresh List rows 
    super.notifyDataSetChanged(); 
} 

@Override 
public boolean isEmpty() { 
    return ((parents == null) || parents.isEmpty()); 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 

@Override 
public boolean hasStableIds() { 
    return true; 
} 

}

我怎麼能做到這一點?

以及如何獲取我的孩子視圖的參考?

tanx

回答

1

檢查下面的代碼。創建一個動畫對象並將其設置爲您需要的視圖。

convertView.startAnimation(animation); 
+0

坦克,它幫助,但它爲所有孩子設置動畫,我怎麼能將它設置爲點擊組孩子? – 2014-09-04 13:51:24

+0

在點擊時設置一個標誌,並將startAnimation()放置成可以根據該標誌工作 – Athul 2014-09-09 06:43:02

相關問題