gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//点击GridView中图片Items后显示一个AlterDialog提示框
new AlertDialog.Builder(MovieActivity.this).setTitle("简介")
.setIcon(MovieActivity.this.getcheckedImageIDPostion(position)).setPositiveButton("返回",new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
}).show();
}
});
为什么
setPositiveButton("返回",new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
}).这一段代码不能写?写上去就报错。。。。
------解决方案--------------------
- Java code
private void openOptionsDialog() { new AlertDialog.Builder(this) .setTitle(R.string.quit_title) .setMessage(R.string.quit_msg) .setPositiveButton(R.string.quit_go, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialoginterface, int i) {finish(); } }) .setNegativeButton(R.string.quit_cancel, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialoginterface, int i) { } }).show();
------解决方案--------------------
弹出Dialog的按钮监听不是onItemclickListener,是楼上的楼上的DialogInterface.OnClickListener,他在show之前没有create
------解决方案--------------------
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setButton(getString(R.string.dialog_exit),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 退出时 清除所有历史记录
HistoryDao hDao = new HistoryDao(
CompanyListActivity.this);
hDao.deleteHistory();
// finish();
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
android.os.Process.killProcess(android.os.Process
.myPid());
}
});
dialog.setButton2(getString(R.string.dialog_cancle),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setTitle(getString(R.string.dialog_prompt_info));
dialog.setMessage(getString(R.string.dialog_exit_app));
dialog 就是你想要的