zoukankan      html  css  js  c++  java
  • android 带listview对话框

    package com.example.dialog2;

    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;

    public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };

    Dialog alertDialog = new AlertDialog.Builder(this).
    setTitle("你喜欢吃哪种水果?")
    .setIcon(R.drawable.ic_launcher)

    //items  和  setMessage 不能同时用
    .setItems(arrayFruit, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(MainActivity.this, arrayFruit[which], Toast.LENGTH_SHORT).show();
    }
    }).
    setNegativeButton("取消", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    }
    }).
    create();
    alertDialog.show();



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    }

  • 相关阅读:
    pandas之DataFrame
    python浅拷贝和深拷贝
    Numpy 机器学习三剑客之Numpy
    django--验证码功能实现
    python基础题
    python武器库
    django-rest-framework
    django--admin组件
    【转载】关于DBUtils中QueryRunner的一些解读
    【转载】java中的反射
  • 原文地址:https://www.cnblogs.com/honeynm/p/4242030.html
Copyright © 2011-2022 走看看