我在Android应用程序中工作。我正在使用一个Gallery小部件,我将Imageview和Imagebutton绑定到该小部件。在按钮上单击我隐藏图库中的一个按钮,但在滚动并返回后隐藏按钮再次可见。是什么导致这种情况发生。滚动后画廊是否再次绑定。如果可能,请提供任何有效链接以解决此问题。
这是我的代码:
public class ImageAdapter extends BaseAdapter {
private int mGalleryItemBackground;
private Activity mContext;
private Integer[] Images;
public ImageAdapter(Activity c,Integer[] images) {
this.mContext = c;
this.Images=images;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGal999lery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGal999lery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return Images.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return 1;
}
public boolean onInterceptTouchEvent(MotionEvent __e) {
return false;
}
public static class ViewHolder{
public ImageView imageView1;
public ImageButton btn1;
public ProgressBar processdialog;
}
//Binding image and button to gallery
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View rowView = convertView;
if(rowView==null)
{
LayoutInflater inflater = mContext.getLayoutInflater();
rowView = inflater.inflate(R.layout.test, null, true);
holder=new ViewHolder();
holder.imageView1=(ImageView) rowView.findViewById(R.id.ImageViewuser);
holder.btn1=(ImageButton)rowView.findViewById(R.id.Download);
holder.processdialog=(ProgressBar)rowView.findViewById(R.id.progressbar_Horizontal);
holder.imageView1.setImageResource(Images[position]);
holder.imageView1.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.imageView1.setBackgroundResource(mGalleryItemBackground);
holder.btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(mContext, position+"", Toast.LENGTH_SHORT).show();
holder.processdialog.setVisibility(View.VISIBLE);
BackgroundAsyncTask dd=new BackgroundAsyncTask();
dd.execute();
}
class BackgroundAsyncTask extends
AsyncTask<Void, Integer, Void> {
int myProgress;
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
Toast.makeText(mContext,
"Download finished", Toast.LENGTH_LONG).show();
holder.processdialog.setVisibility(View.INVISIBLE);
holder.btn1.setVisibility(View.VISIBLE);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
/* Toast.makeText(mContext,
"Downloading", Toast.LENGTH_LONG).show();
myProgress = 0;*/
holder.processdialog.setVisibility(View.VISIBLE);
holder.btn1.setVisibility(View.INVISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
while(myProgress<100){
myProgress++;
publishProgress(myProgress);
SystemClock.sleep(100);
holder.btn1.setVisibility(View.INVISIBLE);
holder.processdialog.setVisibility(View.VISIBLE);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
holder.processdialog.setProgress(values[0]);
}
}
});
}
return rowView;
}
请帮帮我。
提前致谢。
答案 0 :(得分:0)
也许视图可以重复使用。 尝试删除if(rowView == null)。