您好,我有一个画廊,里面有 2 张图片。每次我更改图像时,我都希望在我的布局中使用 textview 来更改其名称。在我的代码中,它只是第一次发生并且保持这种状态。
public class BrowseActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse_activity_layout);
Gallery gallery = (Gallery) findViewById(R.id.browseActivityGallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setSpacing(0);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.building_a,
R.drawable.building_b,
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.browseActivityGalleryStylable);
attr.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView browseActivityTitleTextView = (TextView)findViewById(R.id.browseActivityTitleTextView);
if(position == 0){
browseActivityTitleTextView.setText(" Α'");
}
if(position == 1){
browseActivityTitleTextView.setText(" Β'");
}
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
return imageView;
}
}
}
当我滑动图库时,它应该变为 B',但是当我向后滑动时,它保持 B' 任何人都知道如何解决这个问题?