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

    }

  • 相关阅读:
    百练 2712 细菌繁殖 解题报告
    Elasticsearch常用最全最常用工具清单
    并发工具类使用详解及区别(CountDownLatch、CyclicBarrier、Semaphore、Exchanger)
    Elasticsearch 启动过程详解
    Elasticsearch 编译调试总结
    gradle镜像源配置
    Activiti6详细教程
    CSDN-markdown编辑器语法
    Spring Boot Activiti 整合工作流引擎开发
    less使用语法详解
  • 原文地址:https://www.cnblogs.com/honeynm/p/4242241.html
Copyright © 2011-2022 走看看