リストビューにレートバーを表示し、他の2つのウィジェットも表示するアプリケーションを作成しています。このアダプターで問題が発生したのは、リスト項目を評価し、リストを下にスクロールしてトップに戻ると、評価された項目が明確で、その特定の項目に評価表示がないことです
最初のアイテムに 3 つ星を付けて、下にスクロールして戻ると、0 になったとします。
これが私のコードです:::
package com.AppFavorits;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
public class ListViewCustomAdapter extends BaseAdapter {
public Context context;
LayoutInflater inflator;
ArrayList<Comment> appname;
ArrayList<Comment> Packagenm;
Drawable[] alIcon;
static float[] rating;
public ListViewCustomAdapter(Context context, ArrayList<Comment> appname,
ArrayList<Comment> Packagenm, Drawable[] alIcon) {
super();
this.context = context;
this.appname = appname;
this.Packagenm = Packagenm;
this.alIcon = alIcon;
inflator = LayoutInflater.from(context);
rating = new float[appname.size()];
// Log.i("Parse adapter ", " Date adapter -> " +
// arr_ScheduledDepartureTime[1]);
}
public int getCount() {
// TODO Auto-generated method stub
return appname.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return appname.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public static class ViewHolder {
ImageView imgvFavrowiconappicon;
TextView txvxFavrowiconappname;
RatingBar ratingBar1;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// View vi=convertView;
// View view = null;
ViewHolder viewholder;
if (convertView == null) {
viewholder = new ViewHolder();
convertView = inflator.inflate(R.layout.outbox_list_item, null);
viewholder.ratingBar1 = (RatingBar) convertView
.findViewById(R.id.ratingBar1);
RatingBar.OnRatingBarChangeListener l = new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromTouch) {
/*
* Integer myPosition=(Integer)ratingBar.getTag(); RowModel
* model=getModel(myPosition);
*
* model.rating=rating;
*
* LinearLayout parent=(LinearLayout)ratingBar.getParent();
* TextView label=(TextView)parent.findViewById(R.id.label);
*/
// label.setText(model.toString());
Log.i("TAg", "rate" + rating);
}
};
viewholder.ratingBar1.setOnRatingBarChangeListener(l);
viewholder.txvxFavrowiconappname = (TextView) convertView
.findViewById(R.id.txvxFavrowiconappname);
viewholder.imgvFavrowiconappicon = (ImageView) convertView
.findViewById(R.id.imgvFavrowiconappicon);
// viewholder.ratingBar1 = (RatingBar)
// convertView.findViewById(R.id.ratingBar1);
convertView.setTag(viewholder);
} else {
viewholder = (ViewHolder) convertView.getTag();
}
viewholder.imgvFavrowiconappicon.setImageDrawable(alIcon[position]);
viewholder.txvxFavrowiconappname.setText(appname.get(position)
.toString());
viewholder.ratingBar1.setTag(new Integer(position));
viewholder.ratingBar1.setRating(0);
/*
* viewholder.ratingBar1.setOnTouchListener(new OnTouchListener() {
*
* @Override public boolean onTouch(View v, MotionEvent event) { if
* (event.getAction() == MotionEvent.ACTION_UP) { // TODO perform your
* action here } return true; } });
*/
return convertView;
}
}