的問題是,當我觸摸星星和更新,它更新 另一個TextView中的價值。我的適配器擴展了CursorAdapter。如果我有 getView()我想我會解決它,但我不知道如何處理 CursorAdapter,因爲我們沒有使用getView()。
就像我在我的Cursor
基於適配器的情況下已經評論說你會使用newView()
和bindView()
方法。下面是一個小例子:
public class CustomAdapter extends CursorAdapter {
private static final int CURSOR_TEXT_COLUMN = 0;
public CustomAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(cursor.getString(CURSOR_TEXT_COLUMN));
holder.progress
.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar,
float rating, boolean fromUser) {
// basic example on how you may update the
// TextView(you could use a tag etc).
// Keep in mind that if you scroll this row and come
// back the value will reset as you need to save the
// new rating in a more persistent way and update
// the progress
View rowView = (View) ratingBar.getParent();
TextView text = (TextView) rowView
.findViewById(R.id.the_text);
text.setText(String.valueOf(rating));
}
});
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater mInflater = LayoutInflater.from(context);
View rowView = mInflater.inflate(R.layout.row_layout, parent,
false);
ViewHolder holder = new ViewHolder();
holder.text = (TextView) rowView.findViewById(R.id.the_text);
holder.progress = (RatingBar) rowView
.findViewById(R.id.the_progress);
rowView.setTag(holder);
return rowView;
}
static class ViewHolder {
TextView text;
RatingBar progress;
}
}
您使用的代碼將與基於非遊標的適配器相同,唯一的區別是您將使用'newView()'和'bindView() '方法。 – Luksprog
我該如何解決呢現在我真的很困惑 –
在自定義適配器中,我使用了標籤,但是我不知道如何在這裏處理標籤 –