码迷,mamicode.com
首页 > 移动开发 > 详细

android dialog

时间:2016-08-26 20:00:48      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

 /**
 * @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

标签:

原文地址:http://www.cnblogs.com/laopo/p/5811403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!