ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
String[] items = {getResources().getString(R.string.menu_item_NxtInc)};
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item,items);
menuList.setAdapter(adapt);
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
TextView textView = (TextView) itemClicked;
String strText = textView.getText().toString();
if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_NxtInc))) {
startActivity(new Intent(EndActivity.this, NxtIncActivity.class));
EndActivity.this.finish();
}
我已使用上面的代码在我的应用程序中创建了一个菜单。如果用户单击字符串menu_item_NxtInc,则会将它们带到下一个活动。我想要发生的是提示出来说你确定要这么做吗?任何人都知道如何实现这一点。感谢
答案 0 :(得分:6)
这很简单
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to do this baby?")
.setCancelable(false)
.setPositiveButton("Yuss, lets do this", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// fire an intent go to your next activity
}
})
.setNegativeButton("Err, no", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
答案 1 :(得分:0)
在Fragment中,this
处通过getActivity()
。因此它将变成这样。
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());