代码如下:
private Dialog createMusicListDialog =null;
private View textEntryView ;
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case 1:
if (createMusicListDialog == null)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent()) ;
builder.setIcon(R.drawable.dialog);
builder.setTitle("添加列表");
builder.setView(getTextEntryView());
builder.setCancelable(true);
builder.setPositiveButton("确定", addMusicListButtonListener());
createMusicListDialog = builder.create();
}
return createMusicListDialog;
default:
Log.e("music","Attempting to create an unkonwn dialog with an id of " + id);
return null;
}
}
//对话框里面的view
synchronized protected View getTextEntryView()
{
if (textEntryView == null)
{
LayoutInflater factory = LayoutInflater.from(this);
textEntryView = factory.inflate(R.layout.musiclist_add, null);
}
return textEntryView;
}
//按钮处理函数
protected DialogInterface.OnClickListener addMusicListButtonListener()
{
return new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//这里 id 的值 是-1
System.out.println(id);
}
};
}
显示 对话框的代码是 showDialog(1);为什么在按钮的处理函数里面对话框的id是-1 呢,
private Dialog createMusicListDialog =null;
private View textEntryView ;
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case 1:
if (createMusicListDialog == null)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent()) ;
builder.setIcon(R.drawable.dialog);
builder.setTitle("添加列表");
builder.setView(getTextEntryView());
builder.setCancelable(true);
builder.setPositiveButton("确定", addMusicListButtonListener());
createMusicListDialog = builder.create();
}
return createMusicListDialog;
default:
Log.e("music","Attempting to create an unkonwn dialog with an id of " + id);
return null;
}
}
//对话框里面的view
synchronized protected View getTextEntryView()
{
if (textEntryView == null)
{
LayoutInflater factory = LayoutInflater.from(this);
textEntryView = factory.inflate(R.layout.musiclist_add, null);
}
return textEntryView;
}
//按钮处理函数
protected DialogInterface.OnClickListener addMusicListButtonListener()
{
return new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
//这里 id 的值 是-1
System.out.println(id);
}
};
}
显示 对话框的代码是 showDialog(1);为什么在按钮的处理函数里面对话框的id是-1 呢,
解决方案 »
- monkeyrunner 真机测试失败
- 手机连接wifi,怎么获取这个该wifi局域网中所有的IP
- 求问短信数据库中对canonical_addresses表的处理
- 手机RSS阅读器(全国高校竞赛,求高人指点)
- 【求助】做Android应用开发入门问题?
- Url获取InputStream 空指针异常
- Android请求服务器报错了
- GridLayout中addView方法报错的问题
- 弱弱地问一下,下载完SDK,怎么启动AVD
- Android RelativeLayout 包裹GridView GridView 滑动不了,滑动时直接执行了RefreshView刷新框架
- 统计软件安装次数
- Java 解压缩 APK 并重新局部替换文件后打包 怎么弄啊?
setPositiveButton 的button id 为 -1
setNegativeButton 的button id 为 -2
setNeutralButton 的button id 为 -3