在对话框中输入图库视图
我将如何将 GalleryView 放入警报对话框中。我尝试了多种方法,但没有一种有效,并且都导致了错误。非常感谢这
就是我尝试过的
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case NEWPIC_DIALOG:
LayoutInflater lo = LayoutInflater.from(this);
View picDetailView = lo.inflate(R.layout.newpicdialog, null);
AlertDialog.Builder picDetailBuilder = new AlertDialog.Builder(this);
Gallery g = (Gallery) findViewById(R.id.NewPicDialogGallery);
g.setAdapter(new ImageAdapter(DragActivity.this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(DragActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
picDetailBuilder.setTitle("New Picture");
picDetailBuilder.setView(picDetailView);
AlertDialog picDetail = picDetailBuilder.create();
return picDetail;
default:
break;
}
return null;
}
How would I go about putting a GalleryView into an Alert Dialog. I have tried several ways but none have worked and all have caused errors. Thanks so much for the
This is what I have tried
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case NEWPIC_DIALOG:
LayoutInflater lo = LayoutInflater.from(this);
View picDetailView = lo.inflate(R.layout.newpicdialog, null);
AlertDialog.Builder picDetailBuilder = new AlertDialog.Builder(this);
Gallery g = (Gallery) findViewById(R.id.NewPicDialogGallery);
g.setAdapter(new ImageAdapter(DragActivity.this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(DragActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
picDetailBuilder.setTitle("New Picture");
picDetailBuilder.setView(picDetailView);
AlertDialog picDetail = picDetailBuilder.create();
return picDetail;
default:
break;
}
return null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须重写 onPrepareDialog 函数。请尝试以下操作:
You have to override the
onPrepareDialog
function, too. Try the following: