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

    }

  • 相关阅读:
    WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序
    Emgu 学习(4) 使用指针访问图像内存
    SolidWorks学习笔记1
    Emgu 学习(3) 绘图,使用鼠标绘图,使用trackbar
    NModbus4的使用
    C# async await的使用
    Emgu 学习(2) 视频文件播放
    redis-key2
    redis--key1
    rpc优化
  • 原文地址:https://www.cnblogs.com/honeynm/p/4242241.html
Copyright © 2011-2022 走看看