首页 > 代码库 > android dialog
android dialog
/** * @Title MenuTest.java * @package com.example.standardview * @since * @version 1.0.0 * @author Vic Lee * @date Aug 26, 2016-2:10:07 PM */package com.example.standardview;import com.example.standardview.R.menu;import android.app.Activity;import android.app.AlertDialog;import android.app.ListActivity;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.os.Bundle;import android.view.ContextMenu;import android.view.ContextMenu.ContextMenuInfo;import android.view.Menu;import android.view.MenuInflater;import android.view.MenuItem;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.AdapterContextMenuInfo;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;//public class MenuTest extends Activity {public class MenuTest extends ListActivity { ArrayAdapter<String> arrayAdapter; //private String[] mItemStrings=new String[]{"hello1","hello2","hello3"}; private String[] mItemStrings=new String[]{"hello1 Dialog","hello2 Dialog","hello3 Dialog"}; @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); if (position==position) { AlertDialog alertDialog= new AlertDialog.Builder(MenuTest.this) .setTitle("Hello Dialog") .setIcon(android.R.drawable.alert_dark_frame) .setMessage("Do you want to exit?") .setPositiveButton("Yes", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub MenuTest.this.finish(); } }) .setNegativeButton("No", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }).create(); alertDialog.show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); arrayAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mItemStrings); setListAdapter(arrayAdapter); }}
效果:
android dialog
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。