zoukankan      html  css  js  c++  java
  • android 带RadioButton的Dialog

    package com.example.dialog3;

    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.widget.Toast;

    public class MainActivity extends Activity {
    private int selectedFruitIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final String[] Fruit = new String[] {"苹果", "橘子", "草莓", "香蕉"};

    Dialog myDialog = new AlertDialog.Builder(this)
    .setTitle("标题")
    .setIcon(R.drawable.ic_launcher)
    .setSingleChoiceItems(Fruit, 0, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    selectedFruitIndex=which;
    Toast.makeText(MainActivity.this, Fruit[which], Toast.LENGTH_SHORT).show();
    }
    })
    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    //
    }
    })
    .setNegativeButton("取消", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

    }
    })
    .setNeutralButton("详情", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

    }
    })
    .create();

    myDialog.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;
    }

    }

  • 相关阅读:
    Java 流(Stream)、文件(File)和IO
    归并排序(Java)
    TreeMap和TreeSet在排序时如何比较元素?Collections工具类中的sort()方法如何比较元素?
    动态规划—矩阵链乘法
    SQL Server 行列转换
    dropdownlist无刷新传值
    ASP.NET在主题中添加CSS文件
    asp.net网站后台退出后,点后退按钮仍能进,如何安全退出
    下拉框数据绑定两种方式
    win7安装IIS及将网站发布到IIS上
  • 原文地址:https://www.cnblogs.com/honeynm/p/4242241.html
Copyright © 2011-2022 走看看