在我的应用中,我使用了查看寻呼机来显示我的图片库。
从我的图库中删除任何图片后,视图寻呼机应该更新。
我的活动
public class FullScreenViewActivityForSelfImage extends Activity{
@SuppressWarnings("unused")
private Utils utils;
private FullScreenImageAdapterForSelfImage adapter;
private static ViewPager viewPager;
DatabaseHelper db;
ArrayList<Image> aryimages;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen_view);
db=new DatabaseHelper(this);
viewPager = (ViewPager) findViewById(R.id.pager);
aryimages= db.getimages();
Intent i = getIntent();
int position = i.getIntExtra("position", 0);
adapter = new FullScreenImageAdapterForSelfImage(FullScreenViewActivityForSelfImage.this,
aryimages,this);
viewPager.setAdapter(adapter);
// displaying selected image first
viewPager.setCurrentItem(position);
}
public static ViewPager getAdapter() {
return viewPager;
}
}
我的适配器类
public class FullScreenImageAdapterForSelfImage extends PagerAdapter
{
private Activity _activity;
private ArrayList<Image> _imagePaths;
ArrayList<Image> aryimages;
public ImageListAdapter ImageListAdapter;
private LayoutInflater inflater;
private Context context;
int columnWidth,width,cellWidth,padding,height;
DatabaseHelper db;
int i;
String id,name;
// constructor
public FullScreenImageAdapterForSelfImage(Activity activity,
ArrayList<Image> aryimages,Context context) {
this._activity = activity;
this._imagePaths = aryimages;
this.context = context;
db= new DatabaseHelper(_activity);
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
}
我的适配器,其中称为删除服务
btndel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
alertDialog.setTitle("Confirm Delete...");
alertDialog.setMessage("You are about to delete all images of this product continue");
alertDialog.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// Write your code here to execute after dialog
name = _imagePaths.get(position).Image_name.toString();
String imei=db.SelectImeiNo();
id=db.getidbyname(name);
System.out.println("selected imei = "+imei);
System.out.println("selected id = "+id);
dialog.cancel();
WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK, context , "Deleting Image...");
wst.execute(new String[] { Service_url });
}
});
在适配器中我试图刷新
public void handleResponse(String response) {
System.out.println("handle REsponse...got result..."+response);
if(response.equalsIgnoreCase("0"))
{
System.out.println("!!!!!!!!!!Server Busy try again latter!!!!!!!!!!!!!!!!");
Toast.makeText(context.getApplicationContext(), "Server Busy try again latter", Toast.LENGTH_LONG).show();
}
else if(response.equalsIgnoreCase("1"))
{
System.out.println("!!!!!!!!!!!!Image deleted!!!!!!!!!!!!!!!!!!!");
Toast.makeText(context.getApplicationContext(), "Image deleted", Toast.LENGTH_LONG).show();
db.deleteImageSelected(id);
_imagePaths.remove(i);
ImageListAdapter.notifyDataSetChanged();
}
}
图像适配器
public class ImageListAdapter extends BaseAdapter {
//private Context context;
private ArrayList<Image> Img;
private LayoutInflater inflater = null;
public ImageListAdapter(Context context, ArrayList<Image> Image) {
// this.context = context;
this.Img = Image;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return Img.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressLint("InflateParams")
@SuppressWarnings("unused")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
view = inflater.inflate(R.layout.imageshow, null);
} else {
view = convertView;
}
ImageView iv= (ImageView) view.findViewById(R.id.imageshowView1);
TextView name= (TextView) view.findViewById(R.id.Imageshownametv);
TextView id= (TextView) view.findViewById(R.id.Imageshowidtv);
TextView desc= (TextView) view.findViewById(R.id.Imageshowimagedesc);
id.setText(Img.get(position).Image_id);
byte[] I= Img.get(position).image;
System.out.println("Byte array of the image "+I);
Bitmap bp=BitmapFactory.decodeByteArray(I, 0, I.length);
iv.setImageBitmap(bp);
return view;
}
}
但是没有完成
所以请帮帮我......