是否可以在 Android 的对话框中打开一个类?
例如 :
Dialog settingsDialog = new Dialog(this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().
inflate(R.layout.image_pager, null));
settingsDialog.show();
正在打开图像。我怎样才能为加载类而不是 xml 布局做同样的事情?
附加信息:
这是我的 ImagePager 类
public class ImagePopUp extends BaseActivity implements OnClickListener {
private ViewPager pager;
Button boutton_retour;
public static String img;
private DisplayImageOptions options;
String url,image,title;
ArrayList<Post> PostDetails = new ArrayList<Post>();
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main_diaporama_pager);
showViewHolderExtra();
}
private class ImagePagerAdapter extends PagerAdapter {
private String[] images;
private LayoutInflater inflater;
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
ImagePagerAdapter(String[] images) {
this.images = images;
inflater = getLayoutInflater();
}
@Override
public void finishUpdate(View container) {
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object instantiateItem(View view, int position) {
Dialog settingsDialog = new Dialog(ImagePopUp.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout, null));
settingsDialog.show();
final View imageLayout = inflater.inflate(R.layout.item_pager_image, null);
final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.im_pager);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loadinprogress);
imageLoader.displayImage(images[position], imageView, options, new ImageLoadingListener() {
public void onLoadingStarted() {
spinner.setVisibility(View.VISIBLE);
}
public void onLoadingFailed(FailReason failReason) {
String message = null;
switch (failReason) {
case IO_ERROR:
message = "Input/Output error";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(ImagePopUp.this, message, Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
imageView.setImageResource(android.R.drawable.ic_delete);
}
public void onLoadingComplete(Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
Animation anim = AnimationUtils.loadAnimation(ImagePopUp.this, R.anim.fade_in);
imageView.setAnimation(anim);
anim.start();
}
public void onLoadingCancelled() {
// Do nothing
}
});
((ViewPager) view).addView(imageLayout, 0);
return imageLayout;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View container) {
}
}
public void showViewHolderExtra(){
String[] seperated = img.split(";");
Bundle bundle = getIntent().getExtras();
int pagerPosition = bundle.getInt("POSITION", 0);
System.out.println("image: "+ pagerPosition);
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new ImagePagerAdapter(seperated));
pager.setCurrentItem(pagerPosition);
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher)
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.boutton_retour:
finish();
break;
}
}
}
我希望它出现在单击时的对话框中。