Help with getParent() downcast.
- by Preformed Cone
I'm learning android/java and have this example code I can't get to work:
OnRatingBarChangeListener l = new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromTouch) {
Integer myPos=(Integer)ratingBar.getTag();
RowModel model=getModel(myPos);
model.rating = rating;
LinearLayout p=(LinearLayout)ratingBar.getParent();
TextView l=(TextView)p.findViewById(R.id.label);
l.setText(model.toString());
}
};
Everything works except the LinearLayout / getParent() downcast. At runtime it creates a ClassCastException. If I comment out that block of code then everthing works fine. What am I missing?