Propriété de Albiri Sigue
customer 27921 at Fri Mar 11 19:19:45 +0100 2011
102 L’art du développement Android
Nous pouvons alors hériter d’AdapterWrapper pour créer RateableWrapper, qui redéfinit
la méthode getView() tout en laissant le ListAdapter délégué faire "le vrai travail" :
public class RateableWrapper extends AdapterWrapper {
Context ctxt=null;
float[] rates=null;
public RateableWrapper(Context ctxt, ListAdapter delegate) {
super(delegate);
this.ctxt=ctxt;
this.rates=new float[delegate.getCount()];
for (int i=0;i
this.rates[i]=2.0f;
}
}
public View getView(int position, View convertView,
ViewGroup parent) {
ViewWrapper wrap=null;
View row=convertView;
if (convertView==null) {
LinearLayout layout=new LinearLayout(ctxt);
RatingBar rate=new RatingBar(ctxt);
rate.setNumStars(3);
rate.setStepSize(1.0f);
View guts=delegate.getView(position, null, parent);
layout.setOrientation(LinearLayout.HORIZONTAL);
rate.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT));
guts.setLayoutParams(new LinearLayout. LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
RatingBar.OnRatingBarChangeListener l=
new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar,
float rating,
boolean fromTouch) {
rates[(Integer)ratingBar.getTag()]=rating;
}
};
Livre Android.book Page 102 Dimanche, 8. novembre 2009 12:23 12
customer 27921 at Fri Mar 11 19:19:45 +0100 2011
102 L’art du développement Android
Nous pouvons alors hériter d’AdapterWrapper pour créer RateableWrapper, qui redéfinit
la méthode getView() tout en laissant le ListAdapter délégué faire "le vrai travail" :
public class RateableWrapper extends AdapterWrapper {
Context ctxt=null;
float[] rates=null;
public RateableWrapper(Context ctxt, ListAdapter delegate) {
super(delegate);
this.ctxt=ctxt;
this.rates=new float[delegate.getCount()];
for (int i=0;i
}
}
public View getView(int position, View convertView,
ViewGroup parent) {
ViewWrapper wrap=null;
View row=convertView;
if (convertView==null) {
LinearLayout layout=new LinearLayout(ctxt);
RatingBar rate=new RatingBar(ctxt);
rate.setNumStars(3);
rate.setStepSize(1.0f);
View guts=delegate.getView(position, null, parent);
layout.setOrientation(LinearLayout.HORIZONTAL);
rate.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT));
guts.setLayoutParams(new LinearLayout. LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
RatingBar.OnRatingBarChangeListener l=
new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar,
float rating,
boolean fromTouch) {
rates[(Integer)ratingBar.getTag()]=rating;
}
};
Livre Android.book Page 102 Dimanche, 8. novembre 2009 12:23 12
